Remove Client struct
Gemini requests are very simple and leave little room for customization, so a configurable Client is not necessary.
This commit is contained in:
parent
ace66eceb0
commit
891c4fbec4
@ -12,7 +12,6 @@ import (
|
|||||||
"git.sr.ht/~adnano/go-gemini"
|
"git.sr.ht/~adnano/go-gemini"
|
||||||
)
|
)
|
||||||
|
|
||||||
var client gemini.Client
|
|
||||||
var cert tls.Certificate
|
var cert tls.Certificate
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -37,7 +36,7 @@ func makeRequest(url string) {
|
|||||||
}
|
}
|
||||||
req.TLSConfig.InsecureSkipVerify = true
|
req.TLSConfig.InsecureSkipVerify = true
|
||||||
req.TLSConfig.Certificates = append(req.TLSConfig.Certificates, cert)
|
req.TLSConfig.Certificates = append(req.TLSConfig.Certificates, cert)
|
||||||
resp, err := client.Do(req)
|
resp, err := gemini.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
15
gemini.go
15
gemini.go
@ -176,29 +176,26 @@ func (r *Response) Write(w io.Writer) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Client is a Gemini client.
|
// Get makes a request for the provided URL. The host is inferred from the URL.
|
||||||
type Client struct{}
|
func Get(url string) (*Response, error) {
|
||||||
|
|
||||||
// Request makes a request for the provided URL. The host is inferred from the URL.
|
|
||||||
func (c *Client) Request(url string) (*Response, error) {
|
|
||||||
req, err := NewRequest(url)
|
req, err := NewRequest(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return c.Do(req)
|
return Do(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProxyRequest requests the provided URL from the provided host.
|
// 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)
|
req, err := NewProxyRequest(host, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return c.Do(req)
|
return Do(req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do sends a Gemini request and returns a Gemini response.
|
// 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
|
// Connect to the host
|
||||||
conn, err := tls.Dial("tcp", req.Host, &req.TLSConfig)
|
conn, err := tls.Dial("tcp", req.Host, &req.TLSConfig)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user