[feature] Initial commit

This commit is contained in:
2026-03-25 22:16:00 -04:00
parent 2814505fec
commit 7752d82001
10 changed files with 636 additions and 4 deletions

17
pangolin/domain.go Normal file
View File

@@ -0,0 +1,17 @@
package pangolin
type Domain struct {
ID string `json:"domainId"`
BaseDomain string `json:"baseDomain"`
Verified bool `json:"verified"`
Type string `json:"type"`
Failed bool `json:"failed"`
Tries int `json:"tries"`
ConfigManaged bool `json:"configManaged"`
CertResolver string `json:"certResolver"`
PreferWildcardCert *bool `json:"preferWildcardCert"`
}
type DomainResponse struct {
Domains []Domain `json:"domains"`
}

103
pangolin/pangolin.go Normal file
View File

@@ -0,0 +1,103 @@
package pangolin
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/auroradevllc/apiclient"
)
func New(apiUrl, apiKey string) *Client {
return &Client{
apiUrl: apiUrl,
apiKey: apiKey,
}
}
type Client struct {
apiUrl string
apiKey string
debug bool
}
type Response[V any] struct {
Success bool `json:"success"`
Error bool `json:"error"`
Message string `json:"message"`
Pagination struct {
Total int `json:"total"`
PageSize int `json:"pageSize"`
Page int `json:"page"`
}
Data V `json:"data"`
}
func (p *Client) Domains(orgID string) ([]Domain, error) {
var response Response[DomainResponse]
if err := p.doRequestJSON(http.MethodGet, "/org/"+orgID+"/domains", nil, &response); err != nil {
return nil, err
}
return response.Data.Domains, nil
}
func (p *Client) Resources(orgID string) ([]Resource, error) {
var response Response[ResourceResponse]
if err := p.doRequestJSON(http.MethodGet, "/org/"+orgID+"/resources?pageSize=1000", nil, &response); err != nil {
return nil, err
}
return response.Data.Resources, nil
}
func (p *Client) doRequest(method, uri string, body any) (*apiclient.Response, error) {
opts := []apiclient.Option{
apiclient.WithMethod(method),
apiclient.WithHeader("Authorization", "Bearer "+p.apiKey),
}
if body != nil {
opts = append(opts, apiclient.WithJSON(body))
}
req, err := apiclient.NewRequest(p.apiUrl+"/"+strings.TrimLeft(uri, "/"), opts...)
if err != nil {
return nil, err
}
res, err := req.Send()
if err != nil {
return nil, err
}
return res, nil
}
func (p *Client) doRequestJSON(method, uri string, body any, out any) error {
res, err := p.doRequest(method, uri, body)
if err != nil {
return err
}
// If debugging, we want to read the entire body
if p.debug {
b, err := res.Bytes()
if err != nil {
return err
}
fmt.Println(string(b))
return json.Unmarshal(b, out)
}
return res.Unmarshal(out)
}

31
pangolin/resource.go Normal file
View File

@@ -0,0 +1,31 @@
package pangolin
type Resource struct {
ID int `json:"resourceId"`
NiceID string `json:"niceId"`
Name string `json:"name"`
SSL bool `json:"ssl"`
FullDomain string `json:"fullDomain"`
PasswordID *int `json:"passwordId"`
PincodeID *int `json:"pincodeId"`
Whitelist bool `json:"whitelist"`
HTTP bool `json:"http"`
Protocol string `json:"protocol"`
Enabled bool `json:"enabled"`
DomainID string `json:"domainId"`
Targets []ResourceTarget `json:"targets"`
}
type ResourceTarget struct {
ID int `json:"targetId"`
ResourceID int `json:"resourceId"`
IP string `json:"ip"`
Port int `json:"port"`
Enabled bool `json:"enabled"`
HealthStatus string `json:"healthStatus"`
HcEnabled bool `json:"hcEnabled"`
}
type ResourceResponse struct {
Resources []Resource `json:"resources"`
}