Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
orvice committed Oct 23, 2024
1 parent 3ca0b0e commit 46c75dc
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 96 deletions.
11 changes: 4 additions & 7 deletions cmd/ddns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"strings"
"time"

"github.com/catpie/musdk-go"
"github.com/libdns/libdns"
"github.com/weeon/log"
"github.com/weeon/utils/task"
Expand All @@ -21,27 +20,25 @@ import (

var (
dnsProvider dns.LibDNS
ipGetter ip.IPGetter
muCli *musdk.Client
ipGetter ip.Getter
DNSMode string
)

func Init() error {

var err error
config.GetConfigFromEnv()
ipGetter = ip.NewIfconfigCo()
muCli = musdk.ClientFromEnv(slog.Default())

notify.Init()

notifier, err := notify.NewTelegramNotifier(config.TELEGRAM_TOKEN, config.TELEGRAM_CHATID)
notifier, err := notify.NewTelegramNotifier(config.TelegramToken, config.TelegramChatID)
if err != nil {
log.Errorf("notify init error %v", err)
} else {
notify.AddNotifier(notifier)
}

switch config.DNS_MODE {
switch config.DNSMode {
default:
dnsProvider = dns.NewCloudFlare()
}
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package config
import "github.com/orvice/utils/env"

var (
IpNotifyFormat = "[%s] ip changed, old IP: %s new IP: %s"
IPNotifyFormat = "[%s] ip changed, old IP: %s new IP: %s"
)

func Init() {
inf := env.Get("IP_CHANGE_FORMAT")
if len(inf) != 0 {
IpNotifyFormat = inf
IPNotifyFormat = inf
}
}
55 changes: 0 additions & 55 deletions dns/mu.go

This file was deleted.

5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module github.com/orvice/ddns

require (
github.com/catpie/musdk-go v0.0.0-20230815021801-7d27a00f9c60
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/libdns/cloudflare v0.1.1
github.com/libdns/libdns v0.2.2
Expand All @@ -28,6 +27,4 @@ require (
gopkg.in/yaml.v2 v2.4.0 // indirect
)

go 1.21

toolchain go1.21.0
go 1.23
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/catpie/musdk-go v0.0.0-20230815021801-7d27a00f9c60 h1:2PpsQ5gc13fFhvEG1qtObPAWFveq8TBcL8qbWBuP7cU=
github.com/catpie/musdk-go v0.0.0-20230815021801-7d27a00f9c60/go.mod h1:4W31RomrUPiZpHE9E9biaDASJImNRJDcMjUBJCQQWaY=
github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
Expand Down
27 changes: 7 additions & 20 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,20 @@ package config
import "github.com/orvice/utils/env"

var (
DOMAIN string
UPDATE_TIME int
)

const (
DNS_MODE_MU = "mu"
DOMAIN string
)

var (
DNS_MODE string

NODE_ID int
API_URI string
DNSMode string

TELEGRAM_TOKEN string
TELEGRAM_CHATID int64
TelegramToken string
TelegramChatID int64
)

func GetConfigFromEnv() {
DNS_MODE = env.Get("DNS_MODE", "cf")

DNSMode = env.Get("DNS_MODE", "cf")
DOMAIN = env.Get("DOMAIN")
UPDATE_TIME = env.GetInt("UPDATE_TIME", 300)

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

TELEGRAM_CHATID = int64(env.GetInt("TELEGRAM_CHATID"))
TELEGRAM_TOKEN = env.Get("TELEGRAM_TOKEN")
TelegramChatID = int64(env.GetInt("TELEGRAM_CHATID"))
TelegramToken = env.Get("TELEGRAM_TOKEN")
}
10 changes: 5 additions & 5 deletions internal/ip/ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
)

const (
IpConfigCoAddr = "https://ifconfig.co/json"
ipConfigCoAddr = "https://ifconfig.co/json"
)

type IPResponse struct {
type Response struct {
IP string `json:"ip"`
}

type IPGetter interface {
type Getter interface {
GetIP() (string, error)
}

Expand All @@ -28,7 +28,7 @@ func NewIfconfigCo() *IfconfigCo {
func (i *IfconfigCo) GetIP() (string, error) {
cli := http.Client{}
defer cli.CloseIdleConnections()
resp, err := cli.Get(IpConfigCoAddr)
resp, err := cli.Get(ipConfigCoAddr)
if err != nil {
return "", err
}
Expand All @@ -38,7 +38,7 @@ func (i *IfconfigCo) GetIP() (string, error) {
if err != nil {
return "", err
}
var ret IPResponse
var ret Response
err = json.Unmarshal(s, &ret)
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion notify/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewTelegramNotifier(token string, chatID int64) (*TelegramNotifier, error)
}, nil
}

func (t *TelegramNotifier) Send(ctx context.Context, s string) error {
func (t *TelegramNotifier) Send(_ context.Context, s string) error {
msg := tgbotapi.NewMessage(t.chatID, s)
resp, err := t.bot.Send(msg)
if err != nil {
Expand Down

0 comments on commit 46c75dc

Please sign in to comment.