2020-10-12 14:34:52 -06:00
|
|
|
/*
|
2020-10-24 13:15:32 -06:00
|
|
|
Package gemini implements the Gemini protocol.
|
2020-10-12 14:34:52 -06:00
|
|
|
|
2020-10-27 17:21:33 -06:00
|
|
|
Get makes a Gemini request:
|
2020-10-12 14:34:52 -06:00
|
|
|
|
2020-10-27 17:21:33 -06:00
|
|
|
resp, err := gemini.Get("gemini://example.com")
|
|
|
|
if err != nil {
|
|
|
|
// handle error
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
// ...
|
|
|
|
|
|
|
|
For control over client behavior, create a Client:
|
2020-10-12 14:34:52 -06:00
|
|
|
|
2020-10-31 22:05:00 -06:00
|
|
|
client := &gemini.Client{}
|
2020-10-27 17:21:33 -06:00
|
|
|
resp, err := client.Get("gemini://example.com")
|
2020-10-12 14:34:52 -06:00
|
|
|
if err != nil {
|
|
|
|
// handle error
|
|
|
|
}
|
2020-10-12 14:56:26 -06:00
|
|
|
// ...
|
2020-10-12 14:34:52 -06:00
|
|
|
|
|
|
|
Server is a Gemini server.
|
|
|
|
|
2020-10-31 22:05:00 -06:00
|
|
|
server := &gemini.Server{
|
|
|
|
ReadTimeout: 10 * time.Second,
|
|
|
|
WriteTimeout: 10 * time.Second,
|
|
|
|
}
|
2020-10-12 14:34:52 -06:00
|
|
|
|
2020-10-31 21:05:31 -06:00
|
|
|
Servers should be configured with certificates:
|
2020-10-12 14:34:52 -06:00
|
|
|
|
2020-10-28 14:02:04 -06:00
|
|
|
err := server.Certificates.Load("/var/lib/gemini/certs")
|
2020-10-12 14:56:26 -06:00
|
|
|
if err != nil {
|
|
|
|
// handle error
|
|
|
|
}
|
2020-10-12 14:34:52 -06:00
|
|
|
|
|
|
|
Servers can accept requests for multiple hosts and schemes:
|
|
|
|
|
2020-10-24 13:15:32 -06:00
|
|
|
server.RegisterFunc("example.com", func(w *gemini.ResponseWriter, r *gemini.Request) {
|
2020-10-13 18:22:12 -06:00
|
|
|
fmt.Fprint(w, "Welcome to example.com")
|
2020-10-12 14:34:52 -06:00
|
|
|
})
|
2020-10-24 13:15:32 -06:00
|
|
|
server.RegisterFunc("example.org", func(w *gemini.ResponseWriter, r *gemini.Request) {
|
2020-10-13 18:22:12 -06:00
|
|
|
fmt.Fprint(w, "Welcome to example.org")
|
2020-10-12 14:34:52 -06:00
|
|
|
})
|
2020-10-24 13:15:32 -06:00
|
|
|
server.RegisterFunc("http://example.net", func(w *gemini.ResponseWriter, r *gemini.Request) {
|
2020-10-21 13:57:04 -06:00
|
|
|
fmt.Fprint(w, "Proxied content from http://example.net")
|
2020-10-12 14:34:52 -06:00
|
|
|
})
|
|
|
|
|
|
|
|
To start the server, call ListenAndServe:
|
|
|
|
|
|
|
|
err := server.ListenAndServe()
|
|
|
|
if err != nil {
|
|
|
|
// handle error
|
|
|
|
}
|
|
|
|
*/
|
2020-10-24 13:15:32 -06:00
|
|
|
package gemini
|