go-gemini/examples/server.go
2021-02-21 00:26:30 -05:00

38 lines
723 B
Go

// +build ignore
// This example illustrates a Gemini server.
package main
import (
"context"
"log"
"os"
"time"
"git.sr.ht/~adnano/go-gemini"
"git.sr.ht/~adnano/go-gemini/certificate"
)
func main() {
certificates := &certificate.Store{}
certificates.Register("localhost")
if err := certificates.Load("/var/lib/gemini/certs"); err != nil {
log.Fatal(err)
}
mux := &gemini.ServeMux{}
mux.Handle("/", gemini.FileServer(os.DirFS("/var/www")))
server := &gemini.Server{
Handler: mux,
ReadTimeout: 30 * time.Second,
WriteTimeout: 1 * time.Minute,
GetCertificate: certificates.GetCertificate,
}
if err := server.ListenAndServe(context.Background()); err != nil {
log.Fatal(err)
}
}