/
main.go
37 lines (30 loc) · 880 Bytes
/
main.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
package main
import (
"flag"
"log"
"net/http"
"strings"
"golang.org/x/crypto/acme/autocert"
)
var (
enableHTTPS = flag.Bool("enable-https", false, "Enable listening on port 443 for HTTPS connections and fetching of LetsEncrypt certificates")
hostnames = flag.String("hostnames", "", "A comma-separated whitelist of domains to try asking LetsEncrypt for an TLS cert (unset = any)")
listen = flag.String("listen", ":80", "[IP]:port to listen for HTTP connections.")
)
func main() {
flag.Parse()
if *enableHTTPS {
go serveHTTPS()
}
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(*listen, nil))
}
func serveHTTPS() {
https := http.NewServeMux()
https.HandleFunc("/", handler)
whitelist := []string{}
if *hostnames != "" {
whitelist = strings.Split(*hostnames, ",")
}
log.Fatal(http.Serve(autocert.NewListener(whitelist...), https))
}