Update documentation
This commit is contained in:
parent
0d3230a7d5
commit
7fb1b6c6a4
37
doc.go
37
doc.go
@ -3,55 +3,28 @@ Package gemini implements the Gemini protocol.
|
|||||||
|
|
||||||
Get makes a Gemini request:
|
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")
|
resp, err := gemini.Get("gemini://example.com")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// handle error
|
// handle error
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
For control over client behavior, create a Client:
|
For control over client behavior, create a Client:
|
||||||
|
|
||||||
var client gemini.Client
|
client := &gemini.Client{}
|
||||||
resp, err := client.Get("gemini://example.com")
|
resp, err := client.Get("gemini://example.com")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// handle error
|
// 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.
|
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:
|
Servers should be configured with certificates:
|
||||||
|
|
||||||
|
@ -18,9 +18,6 @@ type Server struct {
|
|||||||
// If Addr is empty, the server will listen on the address ":1965".
|
// If Addr is empty, the server will listen on the address ":1965".
|
||||||
Addr string
|
Addr string
|
||||||
|
|
||||||
// Certificates contains the certificates used by the server.
|
|
||||||
Certificates CertificateStore
|
|
||||||
|
|
||||||
// ReadTimeout is the maximum duration for reading a request.
|
// ReadTimeout is the maximum duration for reading a request.
|
||||||
ReadTimeout time.Duration
|
ReadTimeout time.Duration
|
||||||
|
|
||||||
@ -28,6 +25,9 @@ type Server struct {
|
|||||||
// writes of the response.
|
// writes of the response.
|
||||||
WriteTimeout time.Duration
|
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
|
// CreateCertificate, if not nil, will be called to create a new certificate
|
||||||
// if the current one is expired or missing.
|
// if the current one is expired or missing.
|
||||||
CreateCertificate func(hostname string) (tls.Certificate, error)
|
CreateCertificate func(hostname string) (tls.Certificate, error)
|
||||||
|
Loading…
Reference in New Issue
Block a user