2020-11-09 10:07:49 -07: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
|
|
|
|
}
|
|
|
|
if resp.Status.Class() == gemini.StatusClassSucess {
|
|
|
|
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:
|
|
|
|
|
|
|
|
err := server.Certificates.Load("/var/lib/gemini/certs")
|
|
|
|
if err != nil {
|
|
|
|
// handle error
|
|
|
|
}
|
|
|
|
|
|
|
|
Servers can accept requests for multiple hosts and schemes:
|
|
|
|
|
|
|
|
server.RegisterFunc("example.com", func(w *gemini.ResponseWriter, r *gemini.Request) {
|
|
|
|
fmt.Fprint(w, "Welcome to example.com")
|
|
|
|
})
|
|
|
|
server.RegisterFunc("example.org", func(w *gemini.ResponseWriter, r *gemini.Request) {
|
|
|
|
fmt.Fprint(w, "Welcome to example.org")
|
|
|
|
})
|
|
|
|
server.RegisterFunc("http://example.net", func(w *gemini.ResponseWriter, r *gemini.Request) {
|
|
|
|
fmt.Fprint(w, "Proxied content from http://example.net")
|
|
|
|
})
|
|
|
|
|
|
|
|
To start the server, call ListenAndServe:
|
|
|
|
|
|
|
|
err := server.ListenAndServe()
|
|
|
|
if err != nil {
|
|
|
|
// handle error
|
|
|
|
}
|
|
|
|
*/
|
2020-10-24 13:15:32 -06:00
|
|
|
package gemini
|
2020-09-25 17:09:49 -06:00
|
|
|
|
2020-09-26 14:52:14 -06:00
|
|
|
import (
|
2020-10-13 18:10:04 -06:00
|
|
|
"errors"
|
2020-09-26 14:52:14 -06:00
|
|
|
)
|
|
|
|
|
2020-10-27 17:21:33 -06:00
|
|
|
var crlf = []byte("\r\n")
|
2020-09-25 17:09:49 -06:00
|
|
|
|
2020-10-13 18:10:04 -06:00
|
|
|
// Errors.
|
|
|
|
var (
|
2020-11-05 13:27:12 -07:00
|
|
|
ErrInvalidURL = errors.New("gemini: invalid URL")
|
2020-12-17 23:41:14 -07:00
|
|
|
ErrInvalidRequest = errors.New("gemini: invalid request")
|
2020-11-05 13:27:12 -07:00
|
|
|
ErrInvalidResponse = errors.New("gemini: invalid response")
|
|
|
|
ErrBodyNotAllowed = errors.New("gemini: response body not allowed")
|
2020-10-13 18:10:04 -06:00
|
|
|
)
|