Last active
November 2, 2018 20:24
-
-
Save tafarij/4547e3a5e646497c11843cfbf6759393 to your computer and use it in GitHub Desktop.
Go default TLS client config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func defaultTLSClientConfig(caFilePath string, log logger.Logger) { | |
caCert, err := ioutil.ReadFile(caFilePath) | |
if err != nil { | |
log.Fatalf("Error reading CA cert file '%s'. %s", caFilePath, err.Error()) | |
} | |
caCertPool := x509.NewCertPool() | |
if ok := caCertPool.AppendCertsFromPEM(caCert); !ok { | |
log.Fatalf("Error reading CA cert file '%s'. Invalid content.", caFilePath) | |
} | |
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{ | |
RootCAs: caCertPool, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment