forked from die-net/bench-httpd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
36 lines (30 loc) · 879 Bytes
/
main.go
File metadata and controls
36 lines (30 loc) · 879 Bytes
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
package main
import (
"flag"
"golang.org/x/crypto/acme/autocert"
"log"
"net/http"
"strings"
)
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))
}