Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
orvice committed Aug 16, 2023
1 parent a25ec26 commit 3121809
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
2 changes: 1 addition & 1 deletion cmd/ddns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Init() error {
return err
}
default:
dnsProvider, err = dns.NewCloudFlare(config.CF_API_KEY, config.CF_API_EMAIL, log.GetDefault())
dnsProvider, err = dns.NewCloudFlare()
if err != nil {
return err
}
Expand Down
26 changes: 13 additions & 13 deletions dns/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ import (
"github.com/cloudflare/cloudflare-go"
"github.com/orvice/ddns/config"
"github.com/orvice/ddns/notify"
"github.com/weeon/contract"
)

type CloudFlare struct {
client *cloudflare.API
logger contract.Logger
}

func NewCloudFlare(key, email string, logger contract.Logger) (*CloudFlare, error) {
client, err := cloudflare.New(key, email)
if err != nil {
return nil, err
}

func NewCloudFlare() (*CloudFlare, error) {
key := os.Getenv("CF_KEY")
email := os.Getenv("CF_EMAIL")
token := os.Getenv("CF_TOKEN")

var client *cloudflare.API
var err error

if token != "" {
slog.Info("cf use token")
client, err = cloudflare.NewWithAPIToken(token)
if err != nil {
return nil, err
}
} else {
client, err = cloudflare.New(key, email)
}
if err != nil {
return nil, err
}

return &CloudFlare{
client: client,
logger: logger,
}, nil
}

Expand Down Expand Up @@ -104,7 +104,7 @@ func (c *CloudFlare) UpdateIP(ctx context.Context, domain, ip string) error {
for _, r := range rs {
if r.Type == "A" {
if r.Content == ip {
c.logger.Infof("ip not change...")
slog.Info("ip not change...")
continue
}
oldIP := r.Content
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ require (
github.com/catpie/musdk-go v0.0.0-20230815021801-7d27a00f9c60
github.com/cloudflare/cloudflare-go v0.75.0
github.com/orvice/utils v0.0.0-20180715141935-5b71615d9c36
github.com/weeon/contract v0.0.0-20190520152601-a4ee53bdb563
github.com/weeon/log v0.0.0-20210217051817-63fe9a730962
github.com/weeon/utils v0.0.0-20190524044050-159b91233ff4
github.com/weppos/publicsuffix-go v0.4.0
Expand All @@ -21,6 +20,7 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.4 // indirect
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
github.com/weeon/contract v0.0.0-20190520152601-a4ee53bdb563 // indirect
go.opentelemetry.io/otel v0.16.0 // indirect
go.uber.org/atomic v1.6.0 // indirect
go.uber.org/multierr v1.5.0 // indirect
Expand Down
6 changes: 0 additions & 6 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ const (
var (
DNS_MODE string

CF_API_KEY string
CF_API_EMAIL string

NODE_ID int
API_URI string

Expand All @@ -30,9 +27,6 @@ func GetConfigFromEnv() {
DOMAIN = env.Get("DOMAIN")
UPDATE_TIME = env.GetInt("UPDATE_TIME", 300)

CF_API_KEY = env.Get("CF_API_KEY")
CF_API_EMAIL = env.Get("CF_API_EMAIL")

NODE_ID = env.GetInt("MU_NODE_ID")
API_URI = env.Get("API_URI")

Expand Down

0 comments on commit 3121809

Please sign in to comment.