fix: structure
This commit is contained in:
@@ -3,12 +3,11 @@ package dns
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/dns/aliyun"
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/dns/cloudflare"
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/dns/dnspod"
|
||||
"github.com/Mmx233/BitSrunLoginGo/internal/dns/dynv6"
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@@ -32,24 +31,7 @@ func Run(c *Config) error {
|
||||
case "dnspod":
|
||||
dns, err = dnspod.New(uint64(c.TTL), c.Conf.DnsPod, c.Http.Transport)
|
||||
case "dynv6":
|
||||
url := fmt.Sprintf(
|
||||
"http://dynv6.com/api/update?hostname=%s&token=%s&ipv4=%s", c.Domain, c.Conf.Token, c.IP)
|
||||
// Make the HTTP GET request
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
c.Logger.Error(err)
|
||||
return err
|
||||
}
|
||||
// Read the response body
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
c.Logger.Error(err)
|
||||
return err
|
||||
}
|
||||
// Print the response
|
||||
c.Logger.Debug(string(body))
|
||||
resp.Body.Close()
|
||||
|
||||
dns, err = dynv6.New(c.Domain, c.Conf.Token, c.IP)
|
||||
default:
|
||||
var msg string
|
||||
if c.Provider == "" {
|
||||
|
||||
35
internal/dns/dynv6/dynv6.go
Normal file
35
internal/dns/dynv6/dynv6.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package dynv6
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Dynv6 struct {
|
||||
HostName string
|
||||
Password string
|
||||
IP string
|
||||
}
|
||||
|
||||
func New(Hostname string, Password string, IP string) (*Dynv6, error) {
|
||||
p := Dynv6{HostName: Hostname, Password: Password, IP: IP}
|
||||
return &p, nil
|
||||
}
|
||||
|
||||
func (p Dynv6) SetDomainRecord(domain, ip string) error {
|
||||
url := fmt.Sprintf(
|
||||
"http://dynv6.com/api/update?hostname=%s&token=%s&ipv4=%s",
|
||||
p.HostName,
|
||||
p.Password,
|
||||
p.IP)
|
||||
|
||||
// Make the HTTP GET request
|
||||
time.Sleep(time.Millisecond * 200) // avoid request too fast after login
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user