go-gemini/examples/server/server.go

31 lines
562 B
Go
Raw Normal View History

2020-09-21 21:23:51 +00:00
// +build example
package main
import (
"crypto/tls"
"log"
2020-09-28 22:19:59 +00:00
"git.sr.ht/~adnano/gmi"
2020-09-21 21:23:51 +00:00
)
func main() {
// Load a TLS key pair.
// To generate a TLS key pair, run:
//
// go run -tags=example ../cert
2020-09-27 23:56:33 +00:00
//
2020-09-27 17:50:48 +00:00
cert, err := tls.LoadX509KeyPair("examples/server/localhost.crt", "examples/server/localhost.key")
2020-09-21 21:23:51 +00:00
if err != nil {
log.Fatal(err)
}
2020-09-28 00:20:59 +00:00
mux := &gmi.ServeMux{}
mux.Handle("/", gmi.FileServer(gmi.Dir("/var/www")))
2020-09-21 21:23:51 +00:00
2020-10-12 03:48:18 +00:00
server := gmi.Server{}
server.CertificateStore.Add("localhost", cert)
server.Handle("localhost", mux)
2020-09-21 21:23:51 +00:00
server.ListenAndServe()
}