1
0
Fork 0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-05-13 11:26:07 +02:00

Update documentation

This commit is contained in:
Adnan Maolood 2020-11-01 00:05:00 -04:00
parent 0d3230a7d5
commit 7fb1b6c6a4
2 changed files with 8 additions and 35 deletions

37
doc.go
View File

@ -3,55 +3,28 @@ Package gemini implements the Gemini protocol.
Get makes a Gemini request:
resp, err := gemini.Get("gemini://example.com")
if err != nil {
// handle error
}
// ...
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:
var client gemini.Client
client := &gemini.Client{}
resp, err := client.Get("gemini://example.com")
if err != nil {
// handle error
}
// ...
Clients can load their own list of known hosts:
err := client.KnownHosts.Load("path/to/my/known_hosts")
if err != nil {
// handle error
}
Clients can control when to trust certificates with TrustCertificate:
client.TrustCertificate = func(hostname string, cert *x509.Certificate) gemini.Trust {
return gemini.TrustOnce
}
Clients can create client certificates upon the request of a server:
client.CreateCertificate = func(hostname, path string) (tls.Certificate, error) {
return gemini.CreateCertificate(gemini.CertificateOptions{
Duration: time.Hour,
})
}
Server is a Gemini server.
var server gemini.Server
server := &gemini.Server{
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
Servers should be configured with certificates:

View File

@ -18,9 +18,6 @@ type Server struct {
// If Addr is empty, the server will listen on the address ":1965".
Addr string
// Certificates contains the certificates used by the server.
Certificates CertificateStore
// ReadTimeout is the maximum duration for reading a request.
ReadTimeout time.Duration
@ -28,6 +25,9 @@ type Server struct {
// writes of the response.
WriteTimeout time.Duration
// Certificates contains the certificates used by the server.
Certificates CertificateStore
// CreateCertificate, if not nil, will be called to create a new certificate
// if the current one is expired or missing.
CreateCertificate func(hostname string) (tls.Certificate, error)