add command-line flag options
This commit is contained in:
parent
9d731726e9
commit
0a25e1a89c
12
main.go
12
main.go
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"flag"
|
||||||
"mime"
|
"mime"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
@ -28,6 +29,11 @@ func handleConnection(log logger.Logger, conn net.Conn, h handlers.Handler) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
hostname := flag.String("hostname", "localhost", "comma-separated list of hostnames to generate certificates for")
|
||||||
|
regenCerts := flag.Bool("regenerate-certs", false, "set to true to regenerate cert files")
|
||||||
|
serveFrom := flag.String("path", "./root/", "filepath to serve files from; defaults to ./root/")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
log := logger.NewLogger(true)
|
log := logger.NewLogger(true)
|
||||||
|
|
||||||
mime.AddExtensionType(".gemini", "text/gemini")
|
mime.AddExtensionType(".gemini", "text/gemini")
|
||||||
@ -35,9 +41,9 @@ func main() {
|
|||||||
|
|
||||||
err := certificates.TestCertificateExists("./certs/cert.pem", "./certs/key.pem")
|
err := certificates.TestCertificateExists("./certs/cert.pem", "./certs/key.pem")
|
||||||
var cer tls.Certificate
|
var cer tls.Certificate
|
||||||
if err != nil {
|
if err != nil || *regenCerts {
|
||||||
log.Info("Generating new certificate...")
|
log.Info("Generating new certificate...")
|
||||||
key, cert, err := certificates.GenerateKeyPair("localhost")
|
key, cert, err := certificates.GenerateKeyPair(*hostname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("error generating certificates", err)
|
log.Info("error generating certificates", err)
|
||||||
return
|
return
|
||||||
@ -73,6 +79,6 @@ func main() {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
go handleConnection(log, conn, handlers.NewFileHandler("./root/"))
|
go handleConnection(log, conn, handlers.NewFileHandler(*serveFrom))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user