Skip to content

Commit

Permalink
code clane
Browse files Browse the repository at this point in the history
  • Loading branch information
orvice committed Oct 26, 2024
1 parent 45f20e5 commit 1bd84f9
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 20 deletions.
7 changes: 1 addition & 6 deletions cmd/ddns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ func Init() error {
notify.AddNotifier(notifier)
}

switch config.GetConfig().DNSProvider {
case "aliyun":
dnsProvider = dns.NewAliyun()
default:
dnsProvider = dns.NewCloudFlare()
}
dnsProvider = dns.New(config.GetConfig())

return nil
}
Expand Down
11 changes: 0 additions & 11 deletions dns/cloudflare.go

This file was deleted.

17 changes: 17 additions & 0 deletions dns/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dns

import (
"github.com/libdns/alidns"
"github.com/libdns/cloudflare"
"github.com/libdns/libdns"
"github.com/orvice/ddns/internal/config"
)
Expand All @@ -12,6 +13,22 @@ type LibDNS interface {
libdns.RecordSetter
}

func New(conf *config.Config) LibDNS {
switch conf.DNSProvider {
case "cloudflare":
return NewCloudFlare()
case "aliyun":
return NewAliyun()
}
return nil
}

// cloudflare
func NewCloudFlare() LibDNS {
provider := cloudflare.Provider{APIToken: config.GetConfig().CFToken}
return &provider
}

// aliyun
func NewAliyun() LibDNS {
provider := alidns.Provider{
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type Config struct {
}

var (
config Config
config = &Config{}
)

func Init() (err error) {
Expand All @@ -28,7 +28,7 @@ func Init() (err error) {
return
}

func GetConfig() Config {
func GetConfig() *Config {
return config
}

Expand All @@ -39,6 +39,6 @@ func LoadConfig(path string) (err error) {
viper.SetConfigType("env")
viper.AutomaticEnv()
// viper.ReadInConfig()
err = viper.Unmarshal(&config)
err = viper.Unmarshal(config)
return
}

0 comments on commit 1bd84f9

Please sign in to comment.