Cleans up url struct creation a bit
This commit is contained in:
parent
7896858fac
commit
4c92870790
36
url.go
36
url.go
|
@ -58,16 +58,17 @@ func MakeUrl(u string) (Url, error) {
|
|||
out.Resource = match[i]
|
||||
}
|
||||
}
|
||||
|
||||
if out.Host == "" {
|
||||
return out, fmt.Errorf("no host")
|
||||
}
|
||||
|
||||
out.Scheme = strings.ToLower(out.Scheme)
|
||||
|
||||
if out.Scheme == "" {
|
||||
out.Scheme = "gopher"
|
||||
}
|
||||
|
||||
if out.Host == "" {
|
||||
return out, fmt.Errorf("no host")
|
||||
}
|
||||
|
||||
if out.Scheme == "gopher" && out.Port == "" {
|
||||
out.Port = "70"
|
||||
} else if out.Scheme == "http" && out.Port == "" {
|
||||
|
@ -76,21 +77,20 @@ func MakeUrl(u string) (Url, error) {
|
|||
out.Port = "443"
|
||||
} else if out.Scheme == "gemini" && out.Port == "" {
|
||||
out.Port = "1965"
|
||||
}
|
||||
|
||||
if out.Scheme == "gopher" && out.Mime == "" {
|
||||
out.Mime = "1"
|
||||
}
|
||||
|
||||
if out.Mime == "" && (out.Resource == "" || out.Resource == "/") && out.Scheme == "gopher" {
|
||||
out.Mime = "1"
|
||||
}
|
||||
|
||||
if out.Mime == "7" && strings.Contains(out.Resource, "\t") {
|
||||
out.Mime = "1"
|
||||
} else if out.Scheme == "telnet" && out.Port == "" {
|
||||
out.Port = "23"
|
||||
}
|
||||
|
||||
if out.Scheme == "gopher" {
|
||||
if out.Mime == "" {
|
||||
out.Mime = "1"
|
||||
}
|
||||
if out.Resource == "" || out.Resource == "/" {
|
||||
out.Mime = "1"
|
||||
}
|
||||
if out.Mime == "7" && strings.Contains(out.Resource, "\t") {
|
||||
out.Mime = "1"
|
||||
}
|
||||
switch out.Mime {
|
||||
case "1", "0", "h", "7":
|
||||
out.DownloadOnly = false
|
||||
|
@ -102,10 +102,6 @@ func MakeUrl(u string) (Url, error) {
|
|||
out.Mime = ""
|
||||
}
|
||||
|
||||
if out.Scheme == "http" || out.Scheme == "https" {
|
||||
out.Mime = ""
|
||||
}
|
||||
|
||||
out.Full = out.Scheme + "://" + out.Host + ":" + out.Port + "/" + out.Mime + out.Resource
|
||||
|
||||
return out, nil
|
||||
|
|
Loading…
Reference in New Issue
Block a user