2020-10-12 14:34:52 -06:00
|
|
|
// +build ignore
|
2020-09-21 15:23:51 -06:00
|
|
|
|
2020-12-17 22:47:30 -07:00
|
|
|
// This example illustrates a Gemini server.
|
|
|
|
|
2020-09-21 15:23:51 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2021-02-20 22:26:30 -07:00
|
|
|
"context"
|
2020-09-21 15:23:51 -06:00
|
|
|
"log"
|
2021-02-17 07:25:44 -07:00
|
|
|
"os"
|
2020-10-13 12:22:15 -06:00
|
|
|
"time"
|
2020-09-21 17:17:10 -06:00
|
|
|
|
2020-10-28 12:59:45 -06:00
|
|
|
"git.sr.ht/~adnano/go-gemini"
|
2021-01-14 19:23:13 -07:00
|
|
|
"git.sr.ht/~adnano/go-gemini/certificate"
|
2020-09-21 15:23:51 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2021-02-20 16:30:49 -07:00
|
|
|
certificates := &certificate.Store{}
|
2021-02-19 16:45:19 -07:00
|
|
|
certificates.Register("localhost")
|
|
|
|
if err := certificates.Load("/var/lib/gemini/certs"); err != nil {
|
|
|
|
log.Fatal(err)
|
2020-10-13 12:22:15 -06:00
|
|
|
}
|
2020-10-12 14:34:52 -06:00
|
|
|
|
2021-02-19 16:45:19 -07:00
|
|
|
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,
|
|
|
|
}
|
2020-09-21 15:23:51 -06:00
|
|
|
|
2021-02-20 22:26:30 -07:00
|
|
|
if err := server.ListenAndServe(context.Background()); err != nil {
|
2020-10-11 22:13:24 -06:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2020-09-21 15:23:51 -06:00
|
|
|
}
|