-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebserver.go
42 lines (37 loc) · 892 Bytes
/
webserver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"crypto/tls"
"net/http"
"github.com/Sirupsen/logrus"
"github.com/gorilla/mux"
"golang.org/x/crypto/acme/autocert"
)
func StartTLSServer(cfg *Config, r *mux.Router) {
m := autocert.Manager{
Prompt: autocert.AcceptTOS,
//HostPolicy: autocert.HostWhitelist(cfg.ServerDomain),
}
var addr string = cfg.ServerAddressTLS
if cfg.ServerAddressTLS == "" {
addr = ":https"
}
s := &http.Server{
Addr: addr,
TLSConfig: &tls.Config{GetCertificate: m.GetCertificate},
Handler: r,
}
logrus.Infof("Starting TLS server on %q", s.Addr)
logrus.Fatal(s.ListenAndServeTLS("", ""))
}
func StartServer(cfg *Config, r *mux.Router) {
var addr string = cfg.ServerAddress
if cfg.ServerAddress == "" {
addr = ":http"
}
s := &http.Server{
Addr: addr,
Handler: r,
}
logrus.Infof("Starting server on %q", s.Addr)
logrus.Fatal(s.ListenAndServe())
}