first commit
This commit is contained in:
commit
4b1861fa9b
14 changed files with 811 additions and 0 deletions
62
hetzner/zones.go
Normal file
62
hetzner/zones.go
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
package hetzner
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"git.readonly.ch/bouzoure/gestion-dns/helpers"
|
||||
)
|
||||
|
||||
type Zone struct {
|
||||
ID string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
TTL int `json:"ttl"`
|
||||
NS []string `json:"ns"`
|
||||
Records []Record `json:"-"`
|
||||
}
|
||||
|
||||
type Zones struct {
|
||||
Zones []Zone `json:"zones"`
|
||||
}
|
||||
|
||||
func GetZones() ([]Zone, error) {
|
||||
var zones Zones
|
||||
|
||||
config, err := helpers.GetConfig()
|
||||
if err != nil {
|
||||
return zones.Zones, err
|
||||
}
|
||||
|
||||
// Create client
|
||||
client := &http.Client{}
|
||||
|
||||
// Create request
|
||||
req, err := http.NewRequest(
|
||||
"GET",
|
||||
"https://dns.hetzner.com/api/v1/zones",
|
||||
nil,
|
||||
)
|
||||
if err != nil {
|
||||
return zones.Zones, err
|
||||
}
|
||||
|
||||
// Headers
|
||||
req.Header.Add("Auth-API-Token", config.Hetzner.ApiToken)
|
||||
|
||||
// Fetch Request
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return zones.Zones, err
|
||||
}
|
||||
|
||||
// Read Response Body
|
||||
respBody, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return zones.Zones, err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(respBody, &zones)
|
||||
|
||||
return zones.Zones, err
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue