调用带有注释参数的http.ServeTLS函数。

huangapple go评论64阅读模式
英文:

Сalling the http ServeTLS function with comments in the argument

问题

我看到了这段代码。

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
    }
}()

ServeTLS 函数位于 net/http 包中。为什么在参数中有注释?如果 ServeTLS 函数从配置中接收证书,为什么还要将其添加到参数中?

ServeTLS 的原型是 func (srv *Server) ServeTLS(l net.Listener, certFile, keyFile string) error

英文:

I saw this code.

	go func() {
		var err error
		if hasCert(s.TLSConfig) {
			err = s.ServeTLS(ln, &quot;&quot; /*certFile*/, &quot;&quot; /*keyFile*/)
		} else {
			err = s.Serve(ln)
		}
		if err != http.ErrServerClosed {
			errs &lt;- 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

答案1

得分: 1

请看 https://pkg.go.dev/crypto/tls#Config

它为TLS配置了许多内容,但没有包括服务器的密钥和证书。因此,在使用 ServeTLS 时指定它们并不是多余的。

英文:

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

huangapple
  • 本文由 发表于 2021年10月1日 20:13:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/69405706.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定