fix(hostinger): DNS aplanado + nameservers, facturacion precios formateados, subscriptions endpoint

This commit is contained in:
Lizandro Guarnizo
2026-05-14 20:17:45 -05:00
parent beb9e9d9eb
commit abecb9b305
3 changed files with 88 additions and 27 deletions
+64 -17
View File
@@ -99,14 +99,20 @@ type HostingerDomain struct {
RegisteredAt string `json:"registered_at"`
}
// HostingerDNSRecord representa un registro DNS.
// HostingerDNSRecord representa un registro DNS aplanado para la vista.
type HostingerDNSRecord struct {
ID int `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Content string `json:"content"`
TTL int `json:"ttl"`
Priority int `json:"priority,omitempty"`
Type string `json:"type"`
Name string `json:"name"`
Content string `json:"content"`
TTL int `json:"ttl"`
}
// HostingerNameServers contiene los nameservers de un dominio.
type HostingerNameServers struct {
NS1 string `json:"ns1"`
NS2 string `json:"ns2"`
NS3 string `json:"ns3"`
NS4 string `json:"ns4"`
}
// HostingerSubscription representa una suscripción de facturación.
@@ -178,23 +184,64 @@ func (c *HostingerClient) GetDomains() ([]HostingerDomain, error) {
return arr, nil
}
// hostingerDNSZone es la estructura interna de la respuesta de zona DNS.
type hostingerDNSZone struct {
Records []HostingerDNSRecord `json:"records"`
// hostingerDNSContent es el valor individual de un registro DNS.
type hostingerDNSContent struct {
Content string `json:"content"`
IsDisabled bool `json:"is_disabled"`
}
// GetDNSRecords obtiene los registros DNS de un dominio.
// Endpoint: GET /dns/v1/zones/{domain} — devuelve un array de zonas con records embebidos.
// hostingerDNSEntry es un grupo de registros del mismo tipo/nombre desde la API.
type hostingerDNSEntry struct {
Name string `json:"name"`
TTL int `json:"ttl"`
Type string `json:"type"`
Records []hostingerDNSContent `json:"records"`
}
// GetDNSRecords obtiene los registros DNS de un dominio y los aplana para la vista.
// Endpoint: GET /dns/v1/zones/{domain} — array de {name, ttl, type, records:[{content}]}
func (c *HostingerClient) GetDNSRecords(domain string) ([]HostingerDNSRecord, error) {
path := fmt.Sprintf("/dns/v1/zones/%s", domain)
var zones []hostingerDNSZone
if err := c.get(path, &zones); err != nil {
body, err := c.getRaw(context.Background(), path)
if err != nil {
return nil, err
}
if len(zones) > 0 {
return zones[0].Records, nil
var entries []hostingerDNSEntry
if err := json.Unmarshal(body, &entries); err != nil {
return nil, fmt.Errorf("hostinger: no se pudo interpretar respuesta DNS: %w", err)
}
return []HostingerDNSRecord{}, nil
var result []HostingerDNSRecord
for _, e := range entries {
for _, r := range e.Records {
result = append(result, HostingerDNSRecord{
Type: e.Type,
Name: e.Name,
Content: r.Content,
TTL: e.TTL,
})
}
}
if result == nil {
result = []HostingerDNSRecord{}
}
return result, nil
}
// GetDomainNameServers obtiene los nameservers del dominio desde el portafolio.
// Endpoint: GET /domains/v1/portfolio/{domain}
func (c *HostingerClient) GetDomainNameServers(domain string) (*HostingerNameServers, error) {
path := fmt.Sprintf("/domains/v1/portfolio/%s", domain)
body, err := c.getRaw(context.Background(), path)
if err != nil {
return nil, err
}
var resp struct {
NameServers HostingerNameServers `json:"name_servers"`
}
if err := json.Unmarshal(body, &resp); err != nil {
return nil, fmt.Errorf("hostinger: no se pudo interpretar nameservers: %w", err)
}
return &resp.NameServers, nil
}
// GetOrders obtiene las suscripciones de facturación.