Update examples
This commit is contained in:
parent
322e66ca1e
commit
3e640c3843
2
cert.go
2
cert.go
@ -60,7 +60,7 @@ func (c *CertificateStore) Load(path string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
hostname := filepath.Base(crtPath)
|
hostname := strings.TrimSuffix(filepath.Base(crtPath), ".crt")
|
||||||
c.store[hostname] = cert
|
c.store[hostname] = cert
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
|
||||||
"crypto/x509"
|
"crypto/x509"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@ -34,16 +33,6 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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 := &gmi.ServeMux{}
|
||||||
handler.HandleFunc("/", welcome)
|
handler.HandleFunc("/", welcome)
|
||||||
handler.HandleFunc("/login", login)
|
handler.HandleFunc("/login", login)
|
||||||
@ -53,7 +42,9 @@ func main() {
|
|||||||
handler.HandleFunc("/logout", logout)
|
handler.HandleFunc("/logout", logout)
|
||||||
|
|
||||||
server := &gmi.Server{}
|
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)
|
server.Handle("localhost", handler)
|
||||||
|
|
||||||
if err := server.ListenAndServe(); err != nil {
|
if err := server.ListenAndServe(); err != nil {
|
||||||
|
@ -3,28 +3,20 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"git.sr.ht/~adnano/gmi"
|
"git.sr.ht/~adnano/gmi"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
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 := &gmi.ServeMux{}
|
||||||
mux.Handle("/", gmi.FileServer(gmi.Dir("/var/www")))
|
mux.Handle("/", gmi.FileServer(gmi.Dir("/var/www")))
|
||||||
|
|
||||||
server := gmi.Server{}
|
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.Handle("localhost", mux)
|
||||||
server.ListenAndServe()
|
server.ListenAndServe()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user