Reuse client and ctx
This commit is contained in:
parent
3718689e02
commit
a94dd6fb44
14
main.go
14
main.go
|
@ -59,11 +59,7 @@ func trustCertificate(hostname string, cert *x509.Certificate) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func do(req *gemini.Request, via []*gemini.Request) (*gemini.Response, *gemini.Request, error) {
|
func do(client gemini.Client, ctx context.Context, req *gemini.Request, via []*gemini.Request) (*gemini.Response, *gemini.Request, error) {
|
||||||
client := gemini.Client{
|
|
||||||
TrustCertificate: trustCertificate,
|
|
||||||
}
|
|
||||||
ctx := context.Background()
|
|
||||||
resp, err := client.Do(ctx, req)
|
resp, err := client.Do(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return resp, req, err
|
return resp, req, err
|
||||||
|
@ -85,7 +81,7 @@ func do(req *gemini.Request, via []*gemini.Request) (*gemini.Response, *gemini.R
|
||||||
target = req.URL.ResolveReference(target)
|
target = req.URL.ResolveReference(target)
|
||||||
redirect := *req
|
redirect := *req
|
||||||
redirect.URL = target
|
redirect.URL = target
|
||||||
return do(&redirect, via)
|
return do(client, ctx, &redirect, via)
|
||||||
}
|
}
|
||||||
if resp.Status.Class() != gemini.StatusSuccess {
|
if resp.Status.Class() != gemini.StatusSuccess {
|
||||||
return resp, req, errors.New(fmt.Sprintf("%d %s", resp.Status, resp.Meta))
|
return resp, req, errors.New(fmt.Sprintf("%d %s", resp.Status, resp.Meta))
|
||||||
|
@ -109,7 +105,11 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, req, err := do(req, nil)
|
client := gemini.Client{
|
||||||
|
TrustCertificate: trustCertificate,
|
||||||
|
}
|
||||||
|
ctx := context.Background()
|
||||||
|
resp, req, err := do(client, ctx, req, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue