dongzi5062 2015-06-13 04:55
浏览 245
已采纳

Golang https服务器以字节数组形式传递certFile和kyeFile

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.

  • 写回答

1条回答 默认 最新

  • dongmeiwei0226 2015-06-13 12:25
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择
  • ¥15 这款软件是什么?需要能满足我的需求
  • ¥15 SpringSecurityOauth2登陆前后request不一致