package main import ( "encoding/json" "fmt" "net/http" "time" ) /* HTTP CLIENT */ var httpClient = &http.Client{Timeout: 20 * time.Second} func apiGet(url string, target any) error { req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return err } req.Header.Set("Authorization", "Bearer "+bearerToken) req.Header.Set("Content-Type", "application/json") resp, err := httpClient.Do(req) if err != nil { return err } defer resp.Body.Close() if resp.StatusCode != http.StatusOK { return fmt.Errorf("HTTP %s", resp.Status) } return json.NewDecoder(resp.Body).Decode(target) } /* API STRUCTS */ type info struct { TotalCount int `json:"totalCount"` } type apiList[T any] struct { Data struct { Result struct { Items []T `json:"items"` Info info `json:"info"` } `json:"result"` } `json:"data"` } type originItem struct { IP string `json:"ip"` Weight int `json:"weight"` Mode string `json:"mode"` } type aliasItem struct { ID int `json:"id"` Domain string `json:"domain"` UseCustomSsl int `json:"useCustomSsl"` UseLetsencryptSsl int `json:"useLetsencryptSsl"` SslExpireDate int64 `json:"sslExpireDate"` CreatedAt int64 `json:"createdAt"` ModifiedAt int64 `json:"modifiedAt"` L7ResourceId int64 `json:"l7ResourceId"` } type whoisResponse struct { Data struct { Result struct { L7ResourceId int64 `json:"l7ResourceId"` L7ResourceName string `json:"l7ResourceName"` CreatedAt int64 `json:"createdAt"` L7ResourceIsActive int `json:"l7ResourceIsActive"` ModifiedAt int64 `json:"modifiedAt"` ProtectedIp string `json:"protectedIp"` Http2Support int `json:"http2Support"` GrpcSupport int `json:"grpcSupport"` WafMode int `json:"wafMode"` WafEnabled int `json:"wafEnabled"` WafProvider string `json:"wafProvider"` WafInstance string `json:"wafInstance"` ServiceIpbanEnabled int `json:"serviceIpbanEnabled"` } `json:"result"` } `json:"data"` }