Add (*Client).Get function

This commit is contained in:
Adnan Maolood
2020-10-27 19:21:33 -04:00
parent 12a9deb1a6
commit 239ec885f7
6 changed files with 137 additions and 149 deletions

View File

@@ -33,15 +33,6 @@ type Request struct {
TLS tls.ConnectionState
}
// hostname returns the host without the port.
func hostname(host string) string {
hostname, _, err := net.SplitHostPort(host)
if err != nil {
return host
}
return hostname
}
// NewRequest returns a new request. The host is inferred from the URL.
func NewRequest(rawurl string) (*Request, error) {
u, err := url.Parse(rawurl)
@@ -54,29 +45,13 @@ func NewRequest(rawurl string) (*Request, error) {
// NewRequestFromURL returns a new request for the given URL.
// The host is inferred from the URL.
func NewRequestFromURL(url *url.URL) (*Request, error) {
// If there is no port, use the default port of 1965
host := url.Host
if url.Port() == "" {
host += ":1965"
}
return &Request{
Host: host,
URL: url,
}, nil
}
// NewRequestTo returns a new request for the provided URL to the provided host.
// The host must contain a port.
func NewRequestTo(rawurl, host string) (*Request, error) {
u, err := url.Parse(rawurl)
if err != nil {
return nil, err
}
return &Request{
Host: host,
URL: u,
}, nil
}