go-gemini/examples/server.go

35 lines
740 B
Go
Raw Normal View History

2020-10-12 14:34:52 -06:00
// +build ignore
2020-09-21 15:23:51 -06:00
package main
import (
"crypto/tls"
2020-09-21 15:23:51 -06:00
"log"
"time"
2020-10-28 12:59:45 -06:00
"git.sr.ht/~adnano/go-gemini"
2020-09-21 15:23:51 -06:00
)
func main() {
2020-10-28 12:59:45 -06:00
var server gemini.Server
server.ReadTimeout = 1 * time.Minute
server.WriteTimeout = 2 * time.Minute
2020-10-28 12:59:45 -06:00
if err := server.Certificates.Load("/var/lib/gemini/certs"); err != nil {
2020-10-12 14:34:52 -06:00
log.Fatal(err)
}
2020-10-28 12:59:45 -06:00
server.CreateCertificate = func(hostname string) (tls.Certificate, error) {
return gemini.CreateCertificate(gemini.CertificateOptions{
2020-10-28 12:59:45 -06:00
DNSNames: []string{hostname},
Duration: time.Minute, // for testing purposes
})
}
2020-10-12 14:34:52 -06:00
2020-10-28 12:59:45 -06:00
var mux gemini.ServeMux
mux.Handle("/", gemini.FileServer(gemini.Dir("/var/www")))
2020-09-21 15:23:51 -06:00
2020-10-21 14:28:50 -06:00
server.Register("localhost", &mux)
2020-10-12 14:34:52 -06:00
if err := server.ListenAndServe(); err != nil {
2020-10-11 22:13:24 -06:00
log.Fatal(err)
}
2020-09-21 15:23:51 -06:00
}