简体   繁体   中英

Auto accept certificates programmatically with go-gin

I am using golang go-gin server for hosting an application. Both the front-end and back-end work over https and both are separate projects. The front-end makes ajax calls to the back-end which is rest API based. If I clear the browser cache (Google Chrome) and try to load the UI it does not communicate with the back-end API initially. Then in another tab I hit the base url ( https://localhost:8080/ ) accept the certificate and then it works. Is there any way to avoid this? I want the front end should auto accept the certificate and not complain about it.

In tls.Config you can find the Certificates attribute, which could be helpful in your situation:

Certificates contains one or more certificate chains to present to the other side of the connection. Server configurations must include at least one certificate or else set GetCertificate.

Then you can use your custom tls.Config to obtain a http.Transport for your purposes

tr := &http.Transport{
    TLSClientConfig: &tls.Config{...custom config attrs...},
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM