Switches to using the url package for url handling
This commit is contained in:
parent
3bac06083d
commit
cf8da7439e
15
main.go
15
main.go
|
@ -10,6 +10,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -217,24 +218,26 @@ func findItemRow(name string, position int, csv [][]string) []string {
|
||||||
|
|
||||||
func retrieve(addr string) (string, error) {
|
func retrieve(addr string) (string, error) {
|
||||||
addr = strings.TrimSpace(addr)
|
addr = strings.TrimSpace(addr)
|
||||||
noprot := strings.Replace(addr, "gemini://", "", 1)
|
u, err := url.Parse(addr)
|
||||||
hostResource := strings.SplitN(noprot, "/", 2)
|
if err != nil {
|
||||||
if strings.LastIndex(hostResource[0], ":") == -1 {
|
return "", fmt.Errorf("Retrieve error, parse url: %s", err.Error())
|
||||||
hostResource[0] = hostResource[0] + ":1965"
|
}
|
||||||
|
if u.Port() == "" {
|
||||||
|
u.Host = u.Host + ":1965"
|
||||||
}
|
}
|
||||||
conf := &tls.Config{
|
conf := &tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
MinVersion: tls.VersionTLS12,
|
MinVersion: tls.VersionTLS12,
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err := tls.DialWithDialer(&net.Dialer{Timeout: timeout}, "tcp", hostResource[0], conf)
|
conn, err := tls.DialWithDialer(&net.Dialer{Timeout: timeout}, "tcp", u.Host, conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("TLS Dial Error: %s", err.Error())
|
return "", fmt.Errorf("TLS Dial Error: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
send := "gemini://" + hostResource[0] + "/" + hostResource[1] + "\r\n"
|
send := u.String() + "\r\n"
|
||||||
|
|
||||||
_, err = conn.Write([]byte(send))
|
_, err = conn.Write([]byte(send))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue