1
0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-12-04 09:18:17 +01:00
go-gemini/doc.go
2021-02-21 00:56:37 -05:00

53 lines
1.4 KiB
Go

/*
Package gemini provides Gemini client and server implementations.
Client is a Gemini client.
client := &gemini.Client{}
resp, err := client.Get("gemini://example.com")
if err != nil {
// handle error
}
defer resp.Body.Close()
// ...
Server is a Gemini server.
server := &gemini.Server{
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
Servers should be configured with certificates:
certificates := &certificate.Store{}
err := certificates.Load("/var/lib/gemini/certs")
if err != nil {
// handle error
}
server.GetCertificate = certificates.GetCertificate
ServeMux is a Gemini request multiplexer.
ServeMux can handle requests for multiple hosts and schemes.
mux := &gemini.ServeMux{}
mux.HandleFunc("example.com", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
fmt.Fprint(w, "Welcome to example.com")
})
mux.HandleFunc("example.org/about.gmi", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
fmt.Fprint(w, "About example.org")
})
mux.HandleFunc("http://example.net", func(ctx context.Context, w gemini.ResponseWriter, r *gemini.Request) {
fmt.Fprint(w, "Proxied content from http://example.net")
})
server.Handler = mux
To start the server, call ListenAndServe:
err := server.ListenAndServe(context.Background())
if err != nil {
// handle error
}
*/
package gemini