From 7fb1b6c6a4759414ac622cf71bf18ab2681de3f5 Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Sun, 1 Nov 2020 00:05:00 -0400 Subject: [PATCH] Update documentation --- doc.go | 37 +++++-------------------------------- server.go | 6 +++--- 2 files changed, 8 insertions(+), 35 deletions(-) diff --git a/doc.go b/doc.go index 0fae695..944adbb 100644 --- a/doc.go +++ b/doc.go @@ -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: diff --git a/server.go b/server.go index 9a46bac..859276a 100644 --- a/server.go +++ b/server.go @@ -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)