Skip to content

Instantly share code, notes, and snippets.

@AmaranthLIS
Created October 19, 2018 23:44
Show Gist options
  • Save AmaranthLIS/22c864eb8addda7bf533d151f0c207cf to your computer and use it in GitHub Desktop.
Save AmaranthLIS/22c864eb8addda7bf533d151f0c207cf to your computer and use it in GitHub Desktop.
package main
import (
"io/ioutil"
"log"
"net/http"
"crypto/tls"
"crypto/x509"
)
func main() {
tlsConfig := &tls.Config{
InsecureSkipVerify: false,
RootCAs: x509.NewCertPool(),
}
b, err := ioutil.ReadFile("./ca.crt")
if err != nil {
log.Fatalf("Could not read the CA certificate: %s", err)
}
if tlsConfig.RootCAs.AppendCertsFromPEM(b) != true {
log.Fatalf("Could not load the CA certificate: %s", err)
}
client := &http.Client{Transport: &http.Transport{TLSClientConfig: tlsConfig}}
r, err := client.Get("https://localhost:9000/")
if err != nil {
log.Fatal(err)
}
log.Printf("StatusCode=%v", r.StatusCode)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment