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