Update examples

This commit is contained in:
adnano 2020-10-12 00:13:24 -04:00
parent 322e66ca1e
commit 3e640c3843
3 changed files with 8 additions and 25 deletions

View File

@ -60,7 +60,7 @@ func (c *CertificateStore) Load(path string) error {
if err != nil {
continue
}
hostname := filepath.Base(crtPath)
hostname := strings.TrimSuffix(filepath.Base(crtPath), ".crt")
c.store[hostname] = cert
}
return nil

View File

@ -3,7 +3,6 @@
package main
import (
"crypto/tls"
"crypto/x509"
"fmt"
"log"
@ -34,16 +33,6 @@ var (
)
func main() {
// Configure a certificate.
// To generate a TLS key pair, run:
//
// go run -tags=example ../cert
//
cert, err := tls.LoadX509KeyPair("examples/server/localhost.crt", "examples/server/localhost.key")
if err != nil {
log.Fatal(err)
}
handler := &gmi.ServeMux{}
handler.HandleFunc("/", welcome)
handler.HandleFunc("/login", login)
@ -53,7 +42,9 @@ func main() {
handler.HandleFunc("/logout", logout)
server := &gmi.Server{}
server.CertificateStore.Add("localhost", cert)
if err := server.CertificateStore.Load("/var/lib/gemini/certs"); err != nil {
log.Fatal(err)
}
server.Handle("localhost", handler)
if err := server.ListenAndServe(); err != nil {

View File

@ -3,28 +3,20 @@
package main
import (
"crypto/tls"
"log"
"git.sr.ht/~adnano/gmi"
)
func main() {
// Load a TLS key pair.
// To generate a TLS key pair, run:
//
// go run -tags=example ../cert
//
cert, err := tls.LoadX509KeyPair("examples/server/localhost.crt", "examples/server/localhost.key")
if err != nil {
log.Fatal(err)
}
mux := &gmi.ServeMux{}
mux.Handle("/", gmi.FileServer(gmi.Dir("/var/www")))
server := gmi.Server{}
server.CertificateStore.Add("localhost", cert)
if err := server.CertificateStore.Load("/var/lib/gemini/certs"); err != nil {
log.Fatal(err)
}
log.Print(server.CertificateStore)
server.Handle("localhost", mux)
server.ListenAndServe()
}