Skip to content

Instantly share code, notes, and snippets.

@tychoish
Created January 22, 2019 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tychoish/c0eb005aa7eec64500611728d8412883 to your computer and use it in GitHub Desktop.
Save tychoish/c0eb005aa7eec64500611728d8412883 to your computer and use it in GitHub Desktop.
func NewClientTLSFromFile(certFile, serverNameOverride string) (TransportCredentials, error) {
b, err := ioutil.ReadFile(certFile)
if err != nil {
return nil, err
}
cp := x509.NewCertPool()
if !cp.AppendCertsFromPEM(b) {
return nil, fmt.Errorf("credentials: failed to append certificates")
}
return NewTLS(&tls.Config{ServerName: serverNameOverride, RootCAs: cp}), nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment