refactor: use switch instead of if
parent
d7e7362b57
commit
f1a1e3aae6
|
@ -61,7 +61,8 @@ func initNameserver(n string) (models.Nameserver, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ns, err
|
return ns, err
|
||||||
}
|
}
|
||||||
if u.Scheme == "sdns" {
|
switch u.Scheme {
|
||||||
|
case "sdns":
|
||||||
stamp, err := dnsstamps.NewServerStampFromString(n)
|
stamp, err := dnsstamps.NewServerStampFromString(n)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ns, err
|
return ns, err
|
||||||
|
@ -77,28 +78,28 @@ func initNameserver(n string) (models.Nameserver, error) {
|
||||||
default:
|
default:
|
||||||
return ns, fmt.Errorf("unsupported protocol: %v", stamp.Proto.String())
|
return ns, fmt.Errorf("unsupported protocol: %v", stamp.Proto.String())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if u.Scheme == "https" {
|
case "https":
|
||||||
ns.Type = models.DOHResolver
|
ns.Type = models.DOHResolver
|
||||||
ns.Address = u.String()
|
ns.Address = u.String()
|
||||||
}
|
|
||||||
if u.Scheme == "tls" {
|
case "tls":
|
||||||
ns.Type = models.DOTResolver
|
ns.Type = models.DOTResolver
|
||||||
if u.Port() == "" {
|
if u.Port() == "" {
|
||||||
ns.Address = net.JoinHostPort(u.Hostname(), models.DefaultTLSPort)
|
ns.Address = net.JoinHostPort(u.Hostname(), models.DefaultTLSPort)
|
||||||
} else {
|
} else {
|
||||||
ns.Address = net.JoinHostPort(u.Hostname(), u.Port())
|
ns.Address = net.JoinHostPort(u.Hostname(), u.Port())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if u.Scheme == "tcp" {
|
case "tcp":
|
||||||
ns.Type = models.TCPResolver
|
ns.Type = models.TCPResolver
|
||||||
if u.Port() == "" {
|
if u.Port() == "" {
|
||||||
ns.Address = net.JoinHostPort(u.Hostname(), models.DefaultTCPPort)
|
ns.Address = net.JoinHostPort(u.Hostname(), models.DefaultTCPPort)
|
||||||
} else {
|
} else {
|
||||||
ns.Address = net.JoinHostPort(u.Hostname(), u.Port())
|
ns.Address = net.JoinHostPort(u.Hostname(), u.Port())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if u.Scheme == "udp" {
|
case "udp":
|
||||||
ns.Type = models.UDPResolver
|
ns.Type = models.UDPResolver
|
||||||
if u.Port() == "" {
|
if u.Port() == "" {
|
||||||
ns.Address = net.JoinHostPort(u.Hostname(), models.DefaultUDPPort)
|
ns.Address = net.JoinHostPort(u.Hostname(), models.DefaultUDPPort)
|
||||||
|
|
Loading…
Reference in New Issue