Skip to content

Commit

Permalink
refactor: use switch instead of if
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-karan committed Apr 25, 2021
1 parent d7e7362 commit f1a1e3a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions internal/app/nameservers.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func initNameserver(n string) (models.Nameserver, error) {
if err != nil {
return ns, err
}
if u.Scheme == "sdns" {
switch u.Scheme {
case "sdns":
stamp, err := dnsstamps.NewServerStampFromString(n)
if err != nil {
return ns, err
Expand All @@ -77,28 +78,28 @@ func initNameserver(n string) (models.Nameserver, error) {
default:
return ns, fmt.Errorf("unsupported protocol: %v", stamp.Proto.String())
}
}
if u.Scheme == "https" {

case "https":
ns.Type = models.DOHResolver
ns.Address = u.String()
}
if u.Scheme == "tls" {

case "tls":
ns.Type = models.DOTResolver
if u.Port() == "" {
ns.Address = net.JoinHostPort(u.Hostname(), models.DefaultTLSPort)
} else {
ns.Address = net.JoinHostPort(u.Hostname(), u.Port())
}
}
if u.Scheme == "tcp" {

case "tcp":
ns.Type = models.TCPResolver
if u.Port() == "" {
ns.Address = net.JoinHostPort(u.Hostname(), models.DefaultTCPPort)
} else {
ns.Address = net.JoinHostPort(u.Hostname(), u.Port())
}
}
if u.Scheme == "udp" {

case "udp":
ns.Type = models.UDPResolver
if u.Port() == "" {
ns.Address = net.JoinHostPort(u.Hostname(), models.DefaultUDPPort)
Expand Down

0 comments on commit f1a1e3a

Please sign in to comment.