Skip to content

Commit

Permalink
Merge pull request #11 from orvice/feat/aliyun-dns
Browse files Browse the repository at this point in the history
aliyun dns support
  • Loading branch information
orvice authored Oct 26, 2024
2 parents 1670591 + 29624e2 commit 4cae15c
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 22 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# ddns

support dns:
* cloudflare
Support dns:

* cloudflare
* aliyun
5 changes: 1 addition & 4 deletions cmd/ddns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ func Init() error {
notify.AddNotifier(notifier)
}

switch config.GetConfig().DNSMode {
default:
dnsProvider = dns.NewCloudFlare()
}
dnsProvider = dns.New(config.GetConfig())

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

This file was deleted.

28 changes: 28 additions & 0 deletions dns/dns.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,39 @@
package dns

import (
"github.com/libdns/alidns"
"github.com/libdns/cloudflare"
"github.com/libdns/libdns"
"github.com/orvice/ddns/internal/config"
)

type LibDNS interface {
libdns.RecordGetter
libdns.RecordAppender
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{
AccKeyID: config.GetConfig().AliyunAccessKeyID,
AccKeySecret: config.GetConfig().AliyunAccessKeySecret,
}
return &provider
}
File renamed without changes.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.23
require (
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/libdns/alidns v1.0.3
github.com/libdns/cloudflare v0.1.1
github.com/libdns/libdns v0.2.2
github.com/spf13/viper v1.18.0
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/libdns/alidns v1.0.3 h1:LFHuGnbseq5+HCeGa1aW8awyX/4M2psB9962fdD2+yQ=
github.com/libdns/alidns v1.0.3/go.mod h1:e18uAG6GanfRhcJj6/tps2rCMzQJaYVcGKT+ELjdjGE=
github.com/libdns/cloudflare v0.1.1 h1:FVPfWwP8zZCqj268LZjmkDleXlHPlFU9KC4OJ3yn054=
github.com/libdns/cloudflare v0.1.1/go.mod h1:9VK91idpOjg6v7/WbjkEW49bSCxj00ALesIFDhJ8PBU=
github.com/libdns/libdns v0.2.0/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40=
github.com/libdns/libdns v0.2.2 h1:O6ws7bAfRPaBsgAYt8MDe2HcNBGC29hkZ9MX2eUSX3s=
github.com/libdns/libdns v0.2.2/go.mod h1:4Bj9+5CQiNMVGf87wjX4CY3HQJypUHRuLvlsfsZqLWQ=
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
Expand Down
13 changes: 9 additions & 4 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@ import (
)

type Config struct {
DNSMode string `mapstructure:"DNS_MODE"`
DNSProvider string `mapstructure:"DNS_PROVIDER"`
Domain string `mapstructure:"DOMAIN"`
TelegramChatID int64 `mapstructure:"TELEGRAM_CHATID"`
TelegramToken string `mapstructure:"TELEGRAM_TOKEN"`

CFToken string `mapstructure:"CF_TOKEN"`

AliyunAccessKeyID string `mapstructure:"ALIYUN_ACCESS_KEY_ID"`
AliyunAccessKeySecret string `mapstructure:"ALIYUN_ACCESS_KEY_SECRET"`
}

var (
config Config
config = &Config{}
)

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

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

Expand All @@ -34,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 4cae15c

Please sign in to comment.