func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler) error
Above is the function that I call to start an https server in Golang. It works without any problem. However, as I have more deployments, I don't want to put my key files everywhere. So I am thinking to let the program download the key file and cert file from a centralized place. If there would be a similar function receiving []byte
as opposed to string
, it would be easy for me to do that. But it seems I don't see such function in the documentations.
Looking at the source of ListenAndServeTLS
it seems that there is no option, it always calls tls.LoadX509KeyPair
. That's unfortunate; possibly worth submitting a feature request.
In the meantime, the ListenAndServeTLS
method is not large, and (other than tcpKeepAliveListener
) it does not use anything non-exported so it'd simple to copy the body of that method to your own function and replace Load509KeyPair
with tls.X509KeyPair
, which does take []byte
of PEM encoded data rather than filenames. (Or perhaps take a tls.Certificate
argument instead.)
E.g. something like https://play.golang.org/p/ui_8dS8ouU