2021-01-10 07:16:50 +01:00
|
|
|
/*
|
|
|
|
Package gemini implements the Gemini protocol.
|
|
|
|
|
|
|
|
Client is a Gemini client.
|
|
|
|
|
|
|
|
client := &gemini.Client{}
|
|
|
|
resp, err := client.Get("gemini://example.com")
|
|
|
|
if err != nil {
|
|
|
|
// handle error
|
|
|
|
}
|
2021-01-15 21:15:16 +01:00
|
|
|
defer resp.Body.Close()
|
2021-01-10 07:16:50 +01:00
|
|
|
// ...
|
|
|
|
|
|
|
|
Server is a Gemini server.
|
|
|
|
|
|
|
|
server := &gemini.Server{
|
2021-01-10 07:21:56 +01:00
|
|
|
ReadTimeout: 10 * time.Second,
|
|
|
|
WriteTimeout: 10 * time.Second,
|
2021-01-10 07:16:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Servers should be configured with certificates:
|
|
|
|
|
|
|
|
err := server.Certificates.Load("/var/lib/gemini/certs")
|
|
|
|
if err != nil {
|
|
|
|
// handle error
|
|
|
|
}
|
|
|
|
|
|
|
|
Servers can accept requests for multiple hosts and schemes:
|
|
|
|
|
2021-02-09 16:00:04 +01:00
|
|
|
server.RegisterFunc("example.com", func(w gemini.ResponseWriter, r *gemini.Request) {
|
2021-01-10 07:16:50 +01:00
|
|
|
fmt.Fprint(w, "Welcome to example.com")
|
|
|
|
})
|
2021-02-09 16:00:04 +01:00
|
|
|
server.RegisterFunc("example.org", func(w gemini.ResponseWriter, r *gemini.Request) {
|
2021-01-10 07:16:50 +01:00
|
|
|
fmt.Fprint(w, "Welcome to example.org")
|
|
|
|
})
|
2021-02-09 16:00:04 +01:00
|
|
|
server.RegisterFunc("http://example.net", func(w gemini.ResponseWriter, r *gemini.Request) {
|
2021-01-10 07:16:50 +01:00
|
|
|
fmt.Fprint(w, "Proxied content from http://example.net")
|
|
|
|
})
|
|
|
|
|
|
|
|
To start the server, call ListenAndServe:
|
|
|
|
|
|
|
|
err := server.ListenAndServe()
|
|
|
|
if err != nil {
|
|
|
|
// handle error
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
package gemini
|