fix: structure

This commit is contained in:
chinhwajie
2024-10-25 17:04:02 +08:00
parent 1d65ea2f4a
commit 7490b4566c
6 changed files with 342 additions and 22 deletions

View 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
}