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