diff options
| author | Adnan Maolood <[email protected]> | 2020-10-28 13:40:25 -0400 |
|---|---|---|
| committer | Adnan Maolood <[email protected]> | 2020-10-28 13:41:24 -0400 |
| commit | fbd97a62dec02ad22b7cf520cfc6ab519ea0e990 (patch) | |
| tree | 8a19117713cddce2d3ed2d31c24bec59fe616a48 /examples/client.go | |
| parent | Add ErrInputRequired and ErrCertificateRequired (diff) | |
| download | go-gemini-fbd97a62dec02ad22b7cf520cfc6ab519ea0e990.tar.xz go-gemini-fbd97a62dec02ad22b7cf520cfc6ab519ea0e990.zip | |
Refactor client certificates
Diffstat (limited to 'examples/client.go')
| -rw-r--r-- | examples/client.go | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/examples/client.go b/examples/client.go index 169f726..71e7915 100644 --- a/examples/client.go +++ b/examples/client.go @@ -46,21 +46,11 @@ func init() { } return err } - client.GetCertificate = func(req *gemini.Request, store *gemini.ClientCertificateStore) *tls.Certificate { - // If the certificate is in the store, return it - if cert, err := store.Lookup(req.URL.Hostname(), req.URL.Path); err == nil { - return cert - } - // Otherwise, generate a certificate - fmt.Println("Generating client certificate for", req.URL.Hostname()+req.URL.Path) - duration := time.Hour - cert, err := gemini.NewCertificate("", duration) - if err != nil { - return nil - } - // Store and return the certificate - store.Add(req.URL.Hostname()+req.URL.Path, cert) - return &cert + client.CreateCertificate = func(hostname, path string) (tls.Certificate, error) { + fmt.Println("Generating client certificate for", hostname, path) + return gemini.CreateCertificate(gemini.CertificateOptions{ + Duration: time.Hour, + }) } client.GetInput = func(prompt string, sensitive bool) (string, bool) { fmt.Printf("%s: ", prompt) @@ -69,8 +59,7 @@ func init() { } } -// sendRequest sends a request to the given URL. -func sendRequest(req *gemini.Request) error { +func doRequest(req *gemini.Request) error { resp, err := client.Do(req) if err != nil { return err @@ -131,7 +120,7 @@ func main() { os.Exit(1) } - if err := sendRequest(req); err != nil { + if err := doRequest(req); err != nil { fmt.Println(err) os.Exit(1) } |