mirror of
https://github.com/taigrr/godns
synced 2025-01-18 04:03:25 -08:00
Merge pull request #59 from ebastos/use_switch_case
Use switch/case to make code easier to follow
This commit is contained in:
commit
41d54f1354
21
utils.go
21
utils.go
@ -181,15 +181,16 @@ func GetIPOnline(configuration *Settings) (string, error) {
|
|||||||
|
|
||||||
// CheckSettings check the format of settings
|
// CheckSettings check the format of settings
|
||||||
func CheckSettings(config *Settings) error {
|
func CheckSettings(config *Settings) error {
|
||||||
if config.Provider == DNSPOD {
|
switch config.Provider {
|
||||||
|
case DNSPOD:
|
||||||
if config.Password == "" && config.LoginToken == "" {
|
if config.Password == "" && config.LoginToken == "" {
|
||||||
return errors.New("password or login token cannot be empty")
|
return errors.New("password or login token cannot be empty")
|
||||||
}
|
}
|
||||||
} else if config.Provider == HE {
|
case HE:
|
||||||
if config.Password == "" {
|
if config.Password == "" {
|
||||||
return errors.New("password cannot be empty")
|
return errors.New("password cannot be empty")
|
||||||
}
|
}
|
||||||
} else if config.Provider == CLOUDFLARE {
|
case CLOUDFLARE:
|
||||||
if config.LoginToken == "" {
|
if config.LoginToken == "" {
|
||||||
if config.Email == "" {
|
if config.Email == "" {
|
||||||
return errors.New("email cannot be empty")
|
return errors.New("email cannot be empty")
|
||||||
@ -198,26 +199,27 @@ func CheckSettings(config *Settings) error {
|
|||||||
return errors.New("password cannot be empty")
|
return errors.New("password cannot be empty")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if config.Provider == ALIDNS {
|
case ALIDNS:
|
||||||
if config.Email == "" {
|
if config.Email == "" {
|
||||||
return errors.New("email cannot be empty")
|
return errors.New("email cannot be empty")
|
||||||
}
|
}
|
||||||
if config.Password == "" {
|
if config.Password == "" {
|
||||||
return errors.New("password cannot be empty")
|
return errors.New("password cannot be empty")
|
||||||
}
|
}
|
||||||
} else if config.Provider == DUCK {
|
case DUCK:
|
||||||
if config.LoginToken == "" {
|
if config.LoginToken == "" {
|
||||||
return errors.New("login token cannot be empty")
|
return errors.New("login token cannot be empty")
|
||||||
}
|
}
|
||||||
} else if config.Provider == GOOGLE {
|
case GOOGLE:
|
||||||
if config.Email == "" {
|
if config.Email == "" {
|
||||||
return errors.New("email cannot be empty")
|
return errors.New("email cannot be empty")
|
||||||
}
|
}
|
||||||
if config.Password == "" {
|
if config.Password == "" {
|
||||||
return errors.New("password cannot be empty")
|
return errors.New("password cannot be empty")
|
||||||
}
|
}
|
||||||
} else {
|
default:
|
||||||
return errors.New("please provide supported DNS provider: DNSPod/HE/AliDNS/Cloudflare/GoogleDomain/DuckDNS")
|
return errors.New("please provide supported DNS provider: DNSPod/HE/AliDNS/Cloudflare/GoogleDomain/DuckDNS")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -237,7 +239,6 @@ func SendTelegramNotify(configuration *Settings, domain, currentIP string) error
|
|||||||
return errors.New("chat id cannot be empty")
|
return errors.New("chat id cannot be empty")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
client := GetHttpClient(configuration)
|
client := GetHttpClient(configuration)
|
||||||
tpl := configuration.Notify.Telegram.MsgTemplate
|
tpl := configuration.Notify.Telegram.MsgTemplate
|
||||||
if tpl == "" {
|
if tpl == "" {
|
||||||
@ -312,11 +313,11 @@ func SendMailNotify(configuration *Settings, domain, currentIP string) error {
|
|||||||
// SendNotify sends notify if IP is changed
|
// SendNotify sends notify if IP is changed
|
||||||
func SendNotify(configuration *Settings, domain, currentIP string) error {
|
func SendNotify(configuration *Settings, domain, currentIP string) error {
|
||||||
err := SendTelegramNotify(configuration, domain, currentIP)
|
err := SendTelegramNotify(configuration, domain, currentIP)
|
||||||
if (err != nil) {
|
if err != nil {
|
||||||
log.Println("Send telegram notification with error:", err.Error())
|
log.Println("Send telegram notification with error:", err.Error())
|
||||||
}
|
}
|
||||||
err = SendMailNotify(configuration, domain, currentIP)
|
err = SendMailNotify(configuration, domain, currentIP)
|
||||||
if (err != nil) {
|
if err != nil {
|
||||||
log.Println("Send email notification with error:", err.Error())
|
log.Println("Send email notification with error:", err.Error())
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user