mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-10 22:49:51 +00:00
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package cdnflysdk
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
func (c *Client) GetSite(req *GetSiteRequest) (*GetSiteResponse, error) {
|
|
params := make(map[string]any)
|
|
jsonData, _ := json.Marshal(req)
|
|
json.Unmarshal(jsonData, ¶ms)
|
|
|
|
result := GetSiteResponse{}
|
|
err := c.sendRequestWithResult(http.MethodGet, fmt.Sprintf("/v1/sites/%s", req.Id), params, &result)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
func (c *Client) UpdateSite(req *UpdateSiteRequest) (*UpdateSiteResponse, error) {
|
|
params := make(map[string]any)
|
|
jsonData, _ := json.Marshal(req)
|
|
json.Unmarshal(jsonData, ¶ms)
|
|
|
|
result := UpdateSiteResponse{}
|
|
err := c.sendRequestWithResult(http.MethodPut, fmt.Sprintf("/v1/sites/%s", req.Id), params, &result)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
func (c *Client) CreateCertificate(req *CreateCertificateRequest) (*CreateCertificateResponse, error) {
|
|
params := make(map[string]any)
|
|
jsonData, _ := json.Marshal(req)
|
|
json.Unmarshal(jsonData, ¶ms)
|
|
|
|
result := CreateCertificateResponse{}
|
|
err := c.sendRequestWithResult(http.MethodPost, "/v1/certs", params, &result)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|
|
|
|
func (c *Client) UpdateCertificate(req *UpdateCertificateRequest) (*UpdateCertificateResponse, error) {
|
|
params := make(map[string]any)
|
|
jsonData, _ := json.Marshal(req)
|
|
json.Unmarshal(jsonData, ¶ms)
|
|
|
|
result := UpdateCertificateResponse{}
|
|
err := c.sendRequestWithResult(http.MethodPut, fmt.Sprintf("/v1/certs/%s", req.Id), params, &result)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &result, nil
|
|
}
|