go-gemini/doc.go

83 lines
2.0 KiB
Go
Raw Normal View History

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")
2020-10-12 14:34:52 -06:00
if err != nil {
// handle error
}
2020-10-12 14:49:35 -06:00
// ...
2020-10-12 14:34:52 -06:00
2020-10-27 17:21:33 -06:00
The client must close the response body when finished with it:
resp, err := gemini.Get("gemini://example.com")
if err != nil {
// handle error
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
// ...
For control over client behavior, create a Client:
2020-10-12 14:34:52 -06:00
2020-10-24 13:15:32 -06:00
var 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:34:52 -06:00
2020-10-27 17:21:33 -06:00
Clients can load their own list of known hosts:
2020-10-12 14:34:52 -06:00
err := client.KnownHosts.Load("path/to/my/known_hosts")
2020-10-12 14:34:52 -06:00
if err != nil {
// handle error
}
Clients can control when to trust certificates with TrustCertificate:
2020-10-24 13:15:32 -06:00
client.TrustCertificate = func(hostname string, cert *x509.Certificate, knownHosts *gemini.KnownHosts) error {
2020-10-12 14:34:52 -06:00
return knownHosts.Lookup(hostname, cert)
}
2020-10-28 14:02:04 -06:00
Clients can create client certificates upon the request of a server:
client.CreateCertificate = func(hostname, path string) *tls.Certificate {
return gemini.CreateCertificate(gemini.CertificateOptions{
Duration: time.Hour,
})
2020-10-12 14:34:52 -06:00
}
Server is a Gemini server.
2020-10-24 13:15:32 -06:00
var server gemini.Server
2020-10-12 14:34:52 -06:00
Servers must be configured with certificates:
2020-10-28 14:02:04 -06:00
err := server.Certificates.Load("/var/lib/gemini/certs")
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