feat: add baishan cdn deployer
This commit is contained in:
116
internal/pkg/vendors/gname-sdk/api.go
vendored
116
internal/pkg/vendors/gname-sdk/api.go
vendored
@@ -1,79 +1,57 @@
|
||||
package gnamesdk
|
||||
|
||||
type BaseResponse interface {
|
||||
GetCode() int
|
||||
GetMsg() string
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
func (c *Client) AddDomainResolution(req *AddDomainResolutionRequest) (*AddDomainResolutionResponse, error) {
|
||||
params := make(map[string]any)
|
||||
jsonData, _ := json.Marshal(req)
|
||||
json.Unmarshal(jsonData, ¶ms)
|
||||
|
||||
result := AddDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/add", params, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
type baseResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
func (c *Client) ModifyDomainResolution(req *ModifyDomainResolutionRequest) (*ModifyDomainResolutionResponse, error) {
|
||||
params := make(map[string]any)
|
||||
jsonData, _ := json.Marshal(req)
|
||||
json.Unmarshal(jsonData, ¶ms)
|
||||
|
||||
result := ModifyDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/edit", params, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetCode() int {
|
||||
return r.Code
|
||||
func (c *Client) DeleteDomainResolution(req *DeleteDomainResolutionRequest) (*DeleteDomainResolutionResponse, error) {
|
||||
params := make(map[string]any)
|
||||
jsonData, _ := json.Marshal(req)
|
||||
json.Unmarshal(jsonData, ¶ms)
|
||||
|
||||
result := DeleteDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/delete", params, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetMsg() string {
|
||||
return r.Msg
|
||||
}
|
||||
func (c *Client) ListDomainResolution(req *ListDomainResolutionRequest) (*ListDomainResolutionResponse, error) {
|
||||
params := make(map[string]any)
|
||||
jsonData, _ := json.Marshal(req)
|
||||
json.Unmarshal(jsonData, ¶ms)
|
||||
|
||||
type AddDomainResolutionRequest struct {
|
||||
ZoneName string `json:"ym"`
|
||||
RecordType string `json:"lx"`
|
||||
RecordName string `json:"zj"`
|
||||
RecordValue string `json:"jlz"`
|
||||
MX int `json:"mx"`
|
||||
TTL int `json:"ttl"`
|
||||
}
|
||||
|
||||
type AddDomainResolutionResponse struct {
|
||||
baseResponse
|
||||
Data int `json:"data"`
|
||||
}
|
||||
|
||||
type ModifyDomainResolutionRequest struct {
|
||||
ID string `json:"jxid"`
|
||||
ZoneName string `json:"ym"`
|
||||
RecordType string `json:"lx"`
|
||||
RecordName string `json:"zj"`
|
||||
RecordValue string `json:"jlz"`
|
||||
MX int `json:"mx"`
|
||||
TTL int `json:"ttl"`
|
||||
}
|
||||
|
||||
type ModifyDomainResolutionResponse struct {
|
||||
baseResponse
|
||||
}
|
||||
|
||||
type DeleteDomainResolutionRequest struct {
|
||||
ZoneName string `json:"ym"`
|
||||
RecordID string `json:"jxid"`
|
||||
}
|
||||
|
||||
type DeleteDomainResolutionResponse struct {
|
||||
baseResponse
|
||||
}
|
||||
|
||||
type ListDomainResolutionRequest struct {
|
||||
ZoneName string `json:"ym"`
|
||||
Page *int `json:"page,omitempty"`
|
||||
PageSize *int `json:"limit,omitempty"`
|
||||
}
|
||||
|
||||
type ListDomainResolutionResponse struct {
|
||||
baseResponse
|
||||
Count int `json:"count"`
|
||||
Data []*ResolutionRecord `json:"data"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"pagesize"`
|
||||
}
|
||||
|
||||
type ResolutionRecord struct {
|
||||
ID string `json:"id"`
|
||||
ZoneName string `json:"ym"`
|
||||
RecordType string `json:"lx"`
|
||||
RecordName string `json:"zjt"`
|
||||
RecordValue string `json:"jxz"`
|
||||
MX int `json:"mx"`
|
||||
result := ListDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/list", params, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
66
internal/pkg/vendors/gname-sdk/client.go
vendored
66
internal/pkg/vendors/gname-sdk/client.go
vendored
@@ -12,80 +12,28 @@ import (
|
||||
"github.com/go-resty/resty/v2"
|
||||
)
|
||||
|
||||
type GnameClient struct {
|
||||
type Client struct {
|
||||
appId string
|
||||
appKey string
|
||||
client *resty.Client
|
||||
}
|
||||
|
||||
func NewGnameClient(appId, appKey string) *GnameClient {
|
||||
func NewClient(appId, appKey string) *Client {
|
||||
client := resty.New()
|
||||
|
||||
return &GnameClient{
|
||||
return &Client{
|
||||
appId: appId,
|
||||
appKey: appKey,
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GnameClient) WithTimeout(timeout time.Duration) *GnameClient {
|
||||
func (c *Client) WithTimeout(timeout time.Duration) *Client {
|
||||
c.client.SetTimeout(timeout)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *GnameClient) AddDomainResolution(req *AddDomainResolutionRequest) (*AddDomainResolutionResponse, error) {
|
||||
params := make(map[string]any)
|
||||
jsonData, _ := json.Marshal(req)
|
||||
json.Unmarshal(jsonData, ¶ms)
|
||||
|
||||
result := AddDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/add", params, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *GnameClient) ModifyDomainResolution(req *ModifyDomainResolutionRequest) (*ModifyDomainResolutionResponse, error) {
|
||||
params := make(map[string]any)
|
||||
jsonData, _ := json.Marshal(req)
|
||||
json.Unmarshal(jsonData, ¶ms)
|
||||
|
||||
result := ModifyDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/edit", params, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *GnameClient) DeleteDomainResolution(req *DeleteDomainResolutionRequest) (*DeleteDomainResolutionResponse, error) {
|
||||
params := make(map[string]any)
|
||||
jsonData, _ := json.Marshal(req)
|
||||
json.Unmarshal(jsonData, ¶ms)
|
||||
|
||||
result := DeleteDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/delete", params, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *GnameClient) ListDomainResolution(req *ListDomainResolutionRequest) (*ListDomainResolutionResponse, error) {
|
||||
params := make(map[string]any)
|
||||
jsonData, _ := json.Marshal(req)
|
||||
json.Unmarshal(jsonData, ¶ms)
|
||||
|
||||
result := ListDomainResolutionResponse{}
|
||||
err := c.sendRequestWithResult("/api/resolution/list", params, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
func (c *GnameClient) generateSignature(params map[string]string) string {
|
||||
func (c *Client) generateSignature(params map[string]string) string {
|
||||
// Step 1: Sort parameters by ASCII order
|
||||
var keys []string
|
||||
for k := range params {
|
||||
@@ -109,7 +57,7 @@ func (c *GnameClient) generateSignature(params map[string]string) string {
|
||||
return strings.ToUpper(fmt.Sprintf("%x", hash))
|
||||
}
|
||||
|
||||
func (c *GnameClient) sendRequest(path string, params map[string]any) (*resty.Response, error) {
|
||||
func (c *Client) sendRequest(path string, params map[string]any) (*resty.Response, error) {
|
||||
if params == nil {
|
||||
params = make(map[string]any)
|
||||
}
|
||||
@@ -136,7 +84,7 @@ func (c *GnameClient) sendRequest(path string, params map[string]any) (*resty.Re
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (c *GnameClient) sendRequestWithResult(path string, params map[string]any, result BaseResponse) error {
|
||||
func (c *Client) sendRequestWithResult(path string, params map[string]any, result BaseResponse) error {
|
||||
resp, err := c.sendRequest(path, params)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
79
internal/pkg/vendors/gname-sdk/models.go
vendored
Normal file
79
internal/pkg/vendors/gname-sdk/models.go
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
package gnamesdk
|
||||
|
||||
type BaseResponse interface {
|
||||
GetCode() int
|
||||
GetMsg() string
|
||||
}
|
||||
|
||||
type baseResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetCode() int {
|
||||
return r.Code
|
||||
}
|
||||
|
||||
func (r *baseResponse) GetMsg() string {
|
||||
return r.Msg
|
||||
}
|
||||
|
||||
type AddDomainResolutionRequest struct {
|
||||
ZoneName string `json:"ym"`
|
||||
RecordType string `json:"lx"`
|
||||
RecordName string `json:"zj"`
|
||||
RecordValue string `json:"jlz"`
|
||||
MX int `json:"mx"`
|
||||
TTL int `json:"ttl"`
|
||||
}
|
||||
|
||||
type AddDomainResolutionResponse struct {
|
||||
baseResponse
|
||||
Data int `json:"data"`
|
||||
}
|
||||
|
||||
type ModifyDomainResolutionRequest struct {
|
||||
ID string `json:"jxid"`
|
||||
ZoneName string `json:"ym"`
|
||||
RecordType string `json:"lx"`
|
||||
RecordName string `json:"zj"`
|
||||
RecordValue string `json:"jlz"`
|
||||
MX int `json:"mx"`
|
||||
TTL int `json:"ttl"`
|
||||
}
|
||||
|
||||
type ModifyDomainResolutionResponse struct {
|
||||
baseResponse
|
||||
}
|
||||
|
||||
type DeleteDomainResolutionRequest struct {
|
||||
ZoneName string `json:"ym"`
|
||||
RecordID string `json:"jxid"`
|
||||
}
|
||||
|
||||
type DeleteDomainResolutionResponse struct {
|
||||
baseResponse
|
||||
}
|
||||
|
||||
type ListDomainResolutionRequest struct {
|
||||
ZoneName string `json:"ym"`
|
||||
Page *int `json:"page,omitempty"`
|
||||
PageSize *int `json:"limit,omitempty"`
|
||||
}
|
||||
|
||||
type ListDomainResolutionResponse struct {
|
||||
baseResponse
|
||||
Count int `json:"count"`
|
||||
Data []*ResolutionRecord `json:"data"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"pagesize"`
|
||||
}
|
||||
|
||||
type ResolutionRecord struct {
|
||||
ID string `json:"id"`
|
||||
ZoneName string `json:"ym"`
|
||||
RecordType string `json:"lx"`
|
||||
RecordName string `json:"zjt"`
|
||||
RecordValue string `json:"jxz"`
|
||||
MX int `json:"mx"`
|
||||
}
|
||||
Reference in New Issue
Block a user