From 330b6e4828d59a6d5fae3cc7a30e6fda0856577b Mon Sep 17 00:00:00 2001 From: tjpcc Date: Sat, 12 Aug 2023 08:48:09 -0600 Subject: add Fetch method to clients which follows redirects There are currently only gopher, gemini, and spartan clients. The finger client will have to implement this when it is written. The Fetch method takes the url as a string for convenience, and parses it into a URL for RoundTrip. Fixes #3 --- gopher/client.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gopher/client.go') diff --git a/gopher/client.go b/gopher/client.go index fad9413..163d0cd 100644 --- a/gopher/client.go +++ b/gopher/client.go @@ -5,6 +5,7 @@ import ( "errors" "io" "net" + neturl "net/url" sr "tildegit.org/tjp/sliderule" ) @@ -53,3 +54,12 @@ func (c Client) RoundTrip(request *sr.Request) (*sr.Response, error) { return &sr.Response{Body: bytes.NewBuffer(response)}, nil } + +// Fetch parses a URL string and fetches the gopher resource. +func (c Client) Fetch(url string) (*sr.Response, error) { + u, err := neturl.Parse(url) + if err != nil { + return nil, err + } + return c.RoundTrip(&sr.Request{URL: u}) +} -- cgit v1.2.3