go-gemini/examples/server/server.go
2020-09-27 20:20:59 -04:00

32 lines
530 B
Go

// +build example
package main
import (
"crypto/tls"
"log"
"git.sr.ht/~adnano/go-gemini"
)
func main() {
// Load a TLS key pair.
// To generate a TLS key pair, run:
//
// go run -tags=example ../cert
//
cert, err := tls.LoadX509KeyPair("examples/server/localhost.crt", "examples/server/localhost.key")
if err != nil {
log.Fatal(err)
}
mux := &gmi.ServeMux{}
mux.Handle("/", gmi.FileServer(gmi.Dir("/var/www")))
server := gmi.Server{
Handler: mux,
Certificate: cert,
}
server.ListenAndServe()
}