diff --git a/doc.go b/doc.go index 98e4fcf..424a3c1 100644 --- a/doc.go +++ b/doc.go @@ -1,7 +1,7 @@ /* Package gmi implements the Gemini protocol. -Send makes a Gemini request: +Send makes a Gemini request with the default client: req := gmi.NewRequest("gemini://example.com") resp, err := gmi.Send(req) @@ -10,18 +10,19 @@ Send makes a Gemini request: } // ... -For control over client behavior, create a Client: +For control over client behavior, create a custom Client: var client gmi.Client - err := client.Send(req) + resp, err := client.Send(req) if err != nil { // handle error } + // ... The default client loads known hosts from "$XDG_DATA_HOME/gemini/known_hosts". Custom clients can load their own list of known hosts: - err := client.KnownHosts.LoadFrom("path/to/my/known_hosts") + err := client.KnownHosts.Load("path/to/my/known_hosts") if err != nil { // handle error } @@ -56,7 +57,10 @@ Server is a Gemini server. Servers must be configured with certificates: - server.CertificateStore.Load("/var/lib/gemini/certs") + err := server.CertificateStore.Load("/var/lib/gemini/certs") + if err != nil { + // handle error + } Servers can accept requests for multiple hosts and schemes: diff --git a/examples/client.go b/examples/client.go index d2819ec..edea321 100644 --- a/examples/client.go +++ b/examples/client.go @@ -20,7 +20,7 @@ var ( func init() { // Initialize the client - client.KnownHosts.Load() // Load known hosts + client.KnownHosts.LoadDefault() // Load known hosts client.TrustCertificate = func(hostname string, cert *x509.Certificate, knownHosts *gmi.KnownHosts) error { err := knownHosts.Lookup(hostname, cert) if err != nil { diff --git a/gemini.go b/gemini.go index 5d8960e..3c137c1 100644 --- a/gemini.go +++ b/gemini.go @@ -75,7 +75,7 @@ func init() { var setupDefaultClientOnce sync.Once func setupDefaultClient() { - DefaultClient.KnownHosts.Load() + DefaultClient.KnownHosts.LoadDefault() } // Send sends a Gemini request and returns a Gemini response. diff --git a/tofu.go b/tofu.go index 55f39cb..356e31b 100644 --- a/tofu.go +++ b/tofu.go @@ -21,22 +21,22 @@ type KnownHosts struct { file *os.File } -// Load loads the known hosts from the default known hosts path, which is +// LoadDefault loads the known hosts from the default known hosts path, which is // $XDG_DATA_HOME/gemini/known_hosts. // It creates the path and any of its parent directories if they do not exist. // KnownHosts will append to the file whenever a certificate is added. -func (k *KnownHosts) Load() error { +func (k *KnownHosts) LoadDefault() error { path, err := defaultKnownHostsPath() if err != nil { return err } - return k.LoadFrom(path) + return k.Load(path) } -// LoadFrom loads the known hosts from the provided path. +// Load loads the known hosts from the provided path. // It creates the path and any of its parent directories if they do not exist. // KnownHosts will append to the file whenever a certificate is added. -func (k *KnownHosts) LoadFrom(path string) error { +func (k *KnownHosts) Load(path string) error { if dir := filepath.Dir(path); dir != "." { err := os.MkdirAll(dir, 0755) if err != nil {