Last active
September 20, 2023 04:30
-
-
Save gocs/17c751c0d4622dc7b6cbf9bbbf7907aa to your computer and use it in GitHub Desktop.
unverified tls wss dial
This file contains 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
rootCAs, err := x509.SystemCertPool() | |
if err != nil { | |
return nil, err | |
} | |
// rootCAs := x509.NewCertPool() | |
pemData, err := os.ReadFile(certfile) | |
if err != nil { | |
return nil, err | |
} | |
// You can also append custom CA certificates if needed | |
rootCAs.AppendCertsFromPEM(pemData) | |
u := url.URL{Scheme: "wss", Host: "localhost:8080", Path: "/ws"} | |
d := *websocket.DefaultDialer | |
d.TLSClientConfig = &tls.Config{ | |
RootCAs: rootCAs, | |
InsecureSkipVerify: os.Getenv("PROD") == "true", // Set to false to enable certificate verification on local development | |
} | |
c, _, err := d.Dial(u.String(), nil) | |
if err != nil { | |
log.Fatalln("ws dial:", err) | |
} | |
defer c.Close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment