I'm trying to modify my Go client and server code to use TLS. In Python I can do ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH)
which will automatically load the system's trusted CA certs and uses secure settings. I'm wondering if there's something similar in Go where it will automatically load trusted CA certificates. I'm not sure exactly what to put for the client's certificates.
I think you're looking for tls.Config
. But keep in mind that Python's ssl.create_default_context
exposes a lot of SSL internals that most people don't need, and you might not need a tls.Config
in your application at all. For instance, net/http
has a http.ListenAndServeTLS()
function which starts a TLS web server with sensible defaults and whatever certificates you provide.