pem and key file path are now configurable

This commit is contained in:
Andreas Neue 2016-08-09 16:52:43 +02:00
parent bae871a524
commit 5e43ee5d38
1 changed files with 13 additions and 4 deletions

View File

@ -117,9 +117,18 @@ func (sv *Server) Run() {
if err == nil {
go sv.listen(laddr)
}
tls := true
pem, err := sv.config.GetString("tls", "pem")
if err != nil {
tls = false
}
key, err := sv.config.GetString("tls", "key")
if err != nil {
tls = false
}
laddr, err = sv.config.GetString("net", "listen_tls")
if err == nil {
go sv.listenTls(laddr)
if err == nil && tls {
go sv.listenTls(laddr, pem, key)
}
for {
err = sv.dispatcher()
@ -159,8 +168,8 @@ func (sv *Server) listen(laddr string) {
}
}
func (sv *Server) listenTls(laddr string) {
cert, err := tls.LoadX509KeyPair("cert/server.pem", "cert/server.key")
func (sv *Server) listenTls(laddr, pem, key string) {
cert, err := tls.LoadX509KeyPair(pem, key)
if err != nil {
xlog.Fatal(err.Error())
}