I saw this code.
go func() {
var err error
if hasCert(s.TLSConfig) {
err = s.ServeTLS(ln, "" /*certFile*/, "" /*keyFile*/)
} else {
err = s.Serve(ln)
}
if err != http.ErrServerClosed {
errs <- err
}
}()
The ServeTLS
is located in net/http. Why are there comments in the arguments? If the ServeTLS function receives certificates from the config, why add it to the arguments.
ServeTLS prototype
func (srv *Server) ServeTLS(l net.Listener, certFile, keyFile string) error
CodePudding user response:
Take a look at https://pkg.go.dev/crypto/tls#Config
It configures many things for TLS, but not server key and cert. So it's not actually redundant to specify them to ServeTLS