A TLS / SSL enabled WebServer in Go, done right - includes valid https certificates.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.1 KiB

package main
import (
"flag"
"fmt"
"os"
"strings"
)
func usage() {
fmt.Fprintf(os.Stderr, "\nusage: go run serve.go [optional flags]\n")
flag.PrintDefaults()
fmt.Println()
os.Exit(2)
}
func main() {
flag.Usage = usage
port := flag.Uint("port", 443, "https port")
certsPath := flag.String("letsencrypt-path", "/etc/letsencrypt/live", "path at which an 'xyz.example.com' containing 'fullchain.pem' and 'privkey.pem' can be found")
defaultHost := flag.String("default-hostname", "localhost.daplie.com", "the default folder to find certificates to use when no matches are found")
flag.Parse()
host := strings.ToLower(*defaultHost)
// See https://groups.google.com/a/letsencrypt.org/forum/#!topic/ca-dev/l1Dd6jzWeu8
/*
if strings.HasPrefix("www.", host) {
fmt.Println("TODO: 'www.' prefixed certs should be obtained for every 'example.com' domain.")
}
host = strings.TrimPrefix("www.", host)
*/
fmt.Printf("Loading Certificates %s/%s/{privkey.pem,fullchain.pem}\n", *certsPath, *defaultHost)
fmt.Printf("Listening on https://%s:%d\n", host, *port)
}