aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradnano <[email protected]>2020-09-24 01:55:41 -0400
committeradnano <[email protected]>2020-09-24 01:55:41 -0400
commit891c4fbec43b97a4fbc1b0a7ebbf3e979d2f43fa (patch)
tree2d8a59a4f31faa71aadad214a9416359601770f1
parentProvide Response with ConnectionState (diff)
downloadgo-gemini-891c4fbec43b97a4fbc1b0a7ebbf3e979d2f43fa.tar.xz
go-gemini-891c4fbec43b97a4fbc1b0a7ebbf3e979d2f43fa.zip
Remove Client struct
Gemini requests are very simple and leave little room for customization, so a configurable Client is not necessary.
-rw-r--r--examples/client/client.go3
-rw-r--r--gemini.go15
2 files changed, 7 insertions, 11 deletions
diff --git a/examples/client/client.go b/examples/client/client.go
index c20dd44..1716955 100644
--- a/examples/client/client.go
+++ b/examples/client/client.go
@@ -12,7 +12,6 @@ import (
"git.sr.ht/~adnano/go-gemini"
)
-var client gemini.Client
var cert tls.Certificate
func init() {
@@ -37,7 +36,7 @@ func makeRequest(url string) {
}
req.TLSConfig.InsecureSkipVerify = true
req.TLSConfig.Certificates = append(req.TLSConfig.Certificates, cert)
- resp, err := client.Do(req)
+ resp, err := gemini.Do(req)
if err != nil {
log.Fatal(err)
}
diff --git a/gemini.go b/gemini.go
index 97c1863..b2bd14b 100644
--- a/gemini.go
+++ b/gemini.go
@@ -176,29 +176,26 @@ func (r *Response) Write(w io.Writer) error {
return nil
}
-// Client is a Gemini client.
-type Client struct{}
-
-// Request makes a request for the provided URL. The host is inferred from the URL.
-func (c *Client) Request(url string) (*Response, error) {
+// Get makes a request for the provided URL. The host is inferred from the URL.
+func Get(url string) (*Response, error) {
req, err := NewRequest(url)
if err != nil {
return nil, err
}
- return c.Do(req)
+ return Do(req)
}
// ProxyRequest requests the provided URL from the provided host.
-func (c *Client) ProxyRequest(host, url string) (*Response, error) {
+func ProxyRequest(host, url string) (*Response, error) {
req, err := NewProxyRequest(host, url)
if err != nil {
return nil, err
}
- return c.Do(req)
+ return Do(req)
}
// Do sends a Gemini request and returns a Gemini response.
-func (c *Client) Do(req *Request) (*Response, error) {
+func Do(req *Request) (*Response, error) {
// Connect to the host
conn, err := tls.Dial("tcp", req.Host, &req.TLSConfig)
if err != nil {