certimate/pkg/sdk3rd/upyun/console/api_upload_https_certificate.go
2025-06-17 16:28:51 +08:00

52 lines
1.2 KiB
Go

package console
import (
"context"
"net/http"
)
type UploadHttpsCertificateRequest struct {
Certificate string `json:"certificate"`
PrivateKey string `json:"private_key"`
}
type UploadHttpsCertificateResponse struct {
apiResponseBase
Data *struct {
apiResponseBaseData
Status int32 `json:"status"`
Result struct {
CertificateId string `json:"certificate_id"`
CommonName string `json:"commonName"`
Serial string `json:"serial"`
} `json:"result"`
} `json:"data,omitempty"`
}
func (c *Client) UploadHttpsCertificate(req *UploadHttpsCertificateRequest) (*UploadHttpsCertificateResponse, error) {
return c.UploadHttpsCertificateWithContext(context.Background(), req)
}
func (c *Client) UploadHttpsCertificateWithContext(ctx context.Context, req *UploadHttpsCertificateRequest) (*UploadHttpsCertificateResponse, error) {
if err := c.ensureCookieExists(); err != nil {
return nil, err
}
httpreq, err := c.newRequest(http.MethodPost, "/api/https/certificate/")
if err != nil {
return nil, err
} else {
httpreq.SetBody(req)
httpreq.SetContext(ctx)
}
result := &UploadHttpsCertificateResponse{}
if _, err := c.doRequestWithResult(httpreq, result); err != nil {
return result, err
}
return result, nil
}