go-gemini/doc.go
2021-02-24 18:50:40 -05:00

56 lines
1.4 KiB
Go

/*
Package gemini provides Gemini client and server implementations.
Client is a Gemini client.
client := &gemini.Client{}
ctx := context.Background()
resp, err := client.Get(ctx, "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{}
certificates.Register("localhost")
err := certificates.Load("/var/lib/gemini/certs")
if err != nil {
// handle error
}
server.GetCertificate = certificates.Get
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:
ctx := context.Background()
err := server.ListenAndServe(ctx)
if err != nil {
// handle error
}
*/
package gemini