2020-10-12 20:34:52 +00:00
|
|
|
// +build ignore
|
2020-09-21 21:23:51 +00:00
|
|
|
|
2020-12-18 05:47:30 +00:00
|
|
|
// This example illustrates a Gemini server.
|
|
|
|
|
2020-09-21 21:23:51 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-10-13 18:22:15 +00:00
|
|
|
"crypto/tls"
|
2020-11-03 04:11:46 +00:00
|
|
|
"crypto/x509/pkix"
|
2020-09-21 21:23:51 +00:00
|
|
|
"log"
|
2020-10-13 18:22:15 +00:00
|
|
|
"time"
|
2020-09-21 23:17:10 +00:00
|
|
|
|
2020-10-28 18:59:45 +00:00
|
|
|
"git.sr.ht/~adnano/go-gemini"
|
2021-01-15 02:23:13 +00:00
|
|
|
"git.sr.ht/~adnano/go-gemini/certificate"
|
2020-09-21 21:23:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-10-28 18:59:45 +00:00
|
|
|
var server gemini.Server
|
2020-11-01 19:20:24 +00:00
|
|
|
server.ReadTimeout = 30 * time.Second
|
|
|
|
server.WriteTimeout = 1 * time.Minute
|
2020-10-28 18:59:45 +00:00
|
|
|
if err := server.Certificates.Load("/var/lib/gemini/certs"); err != nil {
|
2020-10-12 20:34:52 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2020-10-28 18:59:45 +00:00
|
|
|
server.CreateCertificate = func(hostname string) (tls.Certificate, error) {
|
2021-01-15 02:23:13 +00:00
|
|
|
return certificate.Create(certificate.CreateOptions{
|
2020-11-03 04:11:46 +00:00
|
|
|
Subject: pkix.Name{
|
|
|
|
CommonName: hostname,
|
|
|
|
},
|
2020-10-28 18:59:45 +00:00
|
|
|
DNSNames: []string{hostname},
|
2020-11-27 22:54:26 +00:00
|
|
|
Duration: 365 * 24 * time.Hour,
|
2020-10-28 18:59:45 +00:00
|
|
|
})
|
2020-10-13 18:22:15 +00:00
|
|
|
}
|
2020-10-12 20:34:52 +00:00
|
|
|
|
2020-10-28 18:59:45 +00:00
|
|
|
var mux gemini.ServeMux
|
|
|
|
mux.Handle("/", gemini.FileServer(gemini.Dir("/var/www")))
|
2020-09-21 21:23:51 +00:00
|
|
|
|
2020-10-21 20:28:50 +00:00
|
|
|
server.Register("localhost", &mux)
|
2020-10-12 20:34:52 +00:00
|
|
|
if err := server.ListenAndServe(); err != nil {
|
2020-10-12 04:13:24 +00:00
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2020-09-21 21:23:51 +00:00
|
|
|
}
|