Browse Source

Switches to using the url package for url handling

master
sloum 11 months ago
parent
commit
cf8da7439e
  1. 15
      main.go

15
main.go

@ -10,6 +10,7 @@ import (
"io"
"io/ioutil"
"net"
"net/url"
"os"
"os/user"
"path/filepath"
@ -217,24 +218,26 @@ func findItemRow(name string, position int, csv [][]string) []string {
func retrieve(addr string) (string, error) {
addr = strings.TrimSpace(addr)
noprot := strings.Replace(addr, "gemini://", "", 1)
hostResource := strings.SplitN(noprot, "/", 2)
if strings.LastIndex(hostResource[0], ":") == -1 {
hostResource[0] = hostResource[0] + ":1965"
u, err := url.Parse(addr)
if err != nil {
return "", fmt.Errorf("Retrieve error, parse url: %s", err.Error())
}
if u.Port() == "" {
u.Host = u.Host + ":1965"
}
conf := &tls.Config{
InsecureSkipVerify: true,
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 {
return "", fmt.Errorf("TLS Dial Error: %s", err.Error())
}
defer conn.Close()
send := "gemini://" + hostResource[0] + "/" + hostResource[1] + "\r\n"
send := u.String() + "\r\n"
_, err = conn.Write([]byte(send))
if err != nil {

Loading…
Cancel
Save