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 (
|
2020-10-13 12:22:15 -06:00
|
|
|
"crypto/tls"
|
2020-11-02 21:11:46 -07:00
|
|
|
"crypto/x509/pkix"
|
2020-09-21 15:23:51 -06:00
|
|
|
"log"
|
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() {
|
2020-10-28 12:59:45 -06:00
|
|
|
var server gemini.Server
|
2020-11-01 12:20:24 -07:00
|
|
|
server.ReadTimeout = 30 * time.Second
|
|
|
|
server.WriteTimeout = 1 * 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) {
|
2021-01-14 19:23:13 -07:00
|
|
|
return certificate.Create(certificate.CreateOptions{
|
2020-11-02 21:11:46 -07:00
|
|
|
Subject: pkix.Name{
|
|
|
|
CommonName: hostname,
|
|
|
|
},
|
2020-10-28 12:59:45 -06:00
|
|
|
DNSNames: []string{hostname},
|
2020-11-27 15:54:26 -07:00
|
|
|
Duration: 365 * 24 * time.Hour,
|
2020-10-28 12:59:45 -06:00
|
|
|
})
|
2020-10-13 12:22:15 -06:00
|
|
|
}
|
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
|
|
|
|
2021-01-14 20:12:07 -07:00
|
|
|
server.Handle("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
|
|
|
}
|