From 769b24aa882c819a0753938052085cae3b9363ca Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Sun, 15 Jun 2025 20:51:28 +0800 Subject: [PATCH] refactor: clean code --- .../providers/ctcccloud-elb/ctcccloud_elb.go | 10 +++++----- .../providers/ctcccloud-ao/ctcccloud_ao.go | 14 +++++++------- .../providers/ctcccloud-elb/ctcccloud_elb.go | 10 +++++----- .../pkg/sdk3rd/ctyun/ao/api_get_domain_config.go | 2 +- .../ao/{api_list_cert.go => api_list_certs.go} | 12 ++++++------ ...ist_certificate.go => api_list_certificates.go} | 12 ++++++------ ...{api_list_listener.go => api_list_listeners.go} | 12 ++++++------ 7 files changed, 36 insertions(+), 36 deletions(-) rename internal/pkg/sdk3rd/ctyun/ao/{api_list_cert.go => api_list_certs.go} (76%) rename internal/pkg/sdk3rd/ctyun/elb/{api_list_certificate.go => api_list_certificates.go} (70%) rename internal/pkg/sdk3rd/ctyun/elb/{api_list_listener.go => api_list_listeners.go} (78%) diff --git a/internal/pkg/core/deployer/providers/ctcccloud-elb/ctcccloud_elb.go b/internal/pkg/core/deployer/providers/ctcccloud-elb/ctcccloud_elb.go index f1dfb3f6..317f70d2 100644 --- a/internal/pkg/core/deployer/providers/ctcccloud-elb/ctcccloud_elb.go +++ b/internal/pkg/core/deployer/providers/ctcccloud-elb/ctcccloud_elb.go @@ -119,17 +119,17 @@ func (d *DeployerProvider) deployToLoadbalancer(ctx context.Context, cloudCertId default: } - listListenerReq := &ctyunelb.ListListenerRequest{ + listListenersReq := &ctyunelb.ListListenersRequest{ RegionID: typeutil.ToPtr(d.config.RegionId), LoadBalancerID: typeutil.ToPtr(d.config.LoadbalancerId), } - listListenerResp, err := d.sdkClient.ListListener(listListenerReq) - d.logger.Debug("sdk request 'elb.ListListener'", slog.Any("request", listListenerReq), slog.Any("response", listListenerResp)) + listListenersResp, err := d.sdkClient.ListListeners(listListenersReq) + d.logger.Debug("sdk request 'elb.ListListeners'", slog.Any("request", listListenersReq), slog.Any("response", listListenersResp)) if err != nil { - return fmt.Errorf("failed to execute sdk request 'elb.ListListener': %w", err) + return fmt.Errorf("failed to execute sdk request 'elb.ListListeners': %w", err) } - for _, listener := range listListenerResp.ReturnObj { + for _, listener := range listListenersResp.ReturnObj { if strings.EqualFold(listener.Protocol, "HTTPS") { listenerIds = append(listenerIds, listener.ID) } diff --git a/internal/pkg/core/uploader/providers/ctcccloud-ao/ctcccloud_ao.go b/internal/pkg/core/uploader/providers/ctcccloud-ao/ctcccloud_ao.go index fa09e3e5..67711e29 100644 --- a/internal/pkg/core/uploader/providers/ctcccloud-ao/ctcccloud_ao.go +++ b/internal/pkg/core/uploader/providers/ctcccloud-ao/ctcccloud_ao.go @@ -73,19 +73,19 @@ func (u *UploaderProvider) Upload(ctx context.Context, certPEM string, privkeyPE default: } - listCertReq := &ctyunao.ListCertRequest{ + listCertsReq := &ctyunao.ListCertsRequest{ Page: typeutil.ToPtr(listCertPage), PerPage: typeutil.ToPtr(listCertPerPage), UsageMode: typeutil.ToPtr(int32(0)), } - listCertResp, err := u.sdkClient.ListCert(listCertReq) - u.logger.Debug("sdk request 'ao.ListCert'", slog.Any("request", listCertReq), slog.Any("response", listCertResp)) + listCertsResp, err := u.sdkClient.ListCerts(listCertsReq) + u.logger.Debug("sdk request 'ao.ListCerts'", slog.Any("request", listCertsReq), slog.Any("response", listCertsResp)) if err != nil { - return nil, fmt.Errorf("failed to execute sdk request 'ao.ListCert': %w", err) + return nil, fmt.Errorf("failed to execute sdk request 'ao.ListCerts': %w", err) } - if listCertResp.ReturnObj != nil { - for _, certRecord := range listCertResp.ReturnObj.Results { + if listCertsResp.ReturnObj != nil { + for _, certRecord := range listCertsResp.ReturnObj.Results { // 对比证书通用名称 if !strings.EqualFold(certX509.Subject.CommonName, certRecord.CN) { continue @@ -137,7 +137,7 @@ func (u *UploaderProvider) Upload(ctx context.Context, certPEM string, privkeyPE } } - if listCertResp.ReturnObj == nil || len(listCertResp.ReturnObj.Results) < int(listCertPerPage) { + if listCertsResp.ReturnObj == nil || len(listCertsResp.ReturnObj.Results) < int(listCertPerPage) { break } else { listCertPage++ diff --git a/internal/pkg/core/uploader/providers/ctcccloud-elb/ctcccloud_elb.go b/internal/pkg/core/uploader/providers/ctcccloud-elb/ctcccloud_elb.go index f6fa16c9..f43643e1 100644 --- a/internal/pkg/core/uploader/providers/ctcccloud-elb/ctcccloud_elb.go +++ b/internal/pkg/core/uploader/providers/ctcccloud-elb/ctcccloud_elb.go @@ -66,15 +66,15 @@ func (u *UploaderProvider) Upload(ctx context.Context, certPEM string, privkeyPE // 查询证书列表,避免重复上传 // REF: https://eop.ctyun.cn/ebp/ctapiDocument/search?sid=24&api=5692&data=88&isNormal=1&vid=82 - listCertificateReq := &ctyunelb.ListCertificateRequest{ + listCertificatesReq := &ctyunelb.ListCertificatesRequest{ RegionID: typeutil.ToPtr(u.config.RegionId), } - listCertificateResp, err := u.sdkClient.ListCertificate(listCertificateReq) - u.logger.Debug("sdk request 'elb.ListCertificate'", slog.Any("request", listCertificateReq), slog.Any("response", listCertificateResp)) + listCertificatesResp, err := u.sdkClient.ListCertificates(listCertificatesReq) + u.logger.Debug("sdk request 'elb.ListCertificates'", slog.Any("request", listCertificatesReq), slog.Any("response", listCertificatesResp)) if err != nil { - return nil, fmt.Errorf("failed to execute sdk request 'elb.ListCertificate': %w", err) + return nil, fmt.Errorf("failed to execute sdk request 'elb.ListCertificates': %w", err) } else { - for _, certRecord := range listCertificateResp.ReturnObj { + for _, certRecord := range listCertificatesResp.ReturnObj { var isSameCert bool if certRecord.Certificate == certPEM { isSameCert = true diff --git a/internal/pkg/sdk3rd/ctyun/ao/api_get_domain_config.go b/internal/pkg/sdk3rd/ctyun/ao/api_get_domain_config.go index 6085adf6..c7b639f4 100644 --- a/internal/pkg/sdk3rd/ctyun/ao/api_get_domain_config.go +++ b/internal/pkg/sdk3rd/ctyun/ao/api_get_domain_config.go @@ -31,7 +31,7 @@ func (c *Client) GetDomainConfig(req *GetDomainConfigRequest) (*GetDomainConfigR } func (c *Client) GetDomainConfigWithContext(ctx context.Context, req *GetDomainConfigRequest) (*GetDomainConfigResponse, error) { - httpreq, err := c.newRequest(http.MethodGet, "/ctapi/v1/accessone/domain/config") + httpreq, err := c.newRequest(http.MethodPost, "/ctapi/v1/accessone/domain/config") if err != nil { return nil, err } else { diff --git a/internal/pkg/sdk3rd/ctyun/ao/api_list_cert.go b/internal/pkg/sdk3rd/ctyun/ao/api_list_certs.go similarity index 76% rename from internal/pkg/sdk3rd/ctyun/ao/api_list_cert.go rename to internal/pkg/sdk3rd/ctyun/ao/api_list_certs.go index b34c199a..70ba7036 100644 --- a/internal/pkg/sdk3rd/ctyun/ao/api_list_cert.go +++ b/internal/pkg/sdk3rd/ctyun/ao/api_list_certs.go @@ -6,13 +6,13 @@ import ( "strconv" ) -type ListCertRequest struct { +type ListCertsRequest struct { Page *int32 `json:"page,omitempty"` PerPage *int32 `json:"per_page,omitempty"` UsageMode *int32 `json:"usage_mode,omitempty"` } -type ListCertResponse struct { +type ListCertsResponse struct { baseResult ReturnObj *struct { @@ -24,11 +24,11 @@ type ListCertResponse struct { } `json:"returnObj,omitempty"` } -func (c *Client) ListCert(req *ListCertRequest) (*ListCertResponse, error) { - return c.ListCertWithContext(context.Background(), req) +func (c *Client) ListCerts(req *ListCertsRequest) (*ListCertsResponse, error) { + return c.ListCertsWithContext(context.Background(), req) } -func (c *Client) ListCertWithContext(ctx context.Context, req *ListCertRequest) (*ListCertResponse, error) { +func (c *Client) ListCertsWithContext(ctx context.Context, req *ListCertsRequest) (*ListCertsResponse, error) { httpreq, err := c.newRequest(http.MethodGet, "/ctapi/v1/accessone/cert/list") if err != nil { return nil, err @@ -46,7 +46,7 @@ func (c *Client) ListCertWithContext(ctx context.Context, req *ListCertRequest) httpreq.SetContext(ctx) } - result := &ListCertResponse{} + result := &ListCertsResponse{} if _, err := c.doRequestWithResult(httpreq, result); err != nil { return result, err } diff --git a/internal/pkg/sdk3rd/ctyun/elb/api_list_certificate.go b/internal/pkg/sdk3rd/ctyun/elb/api_list_certificates.go similarity index 70% rename from internal/pkg/sdk3rd/ctyun/elb/api_list_certificate.go rename to internal/pkg/sdk3rd/ctyun/elb/api_list_certificates.go index 7a55adfb..6ba1b5a7 100644 --- a/internal/pkg/sdk3rd/ctyun/elb/api_list_certificate.go +++ b/internal/pkg/sdk3rd/ctyun/elb/api_list_certificates.go @@ -5,7 +5,7 @@ import ( "net/http" ) -type ListCertificateRequest struct { +type ListCertificatesRequest struct { ClientToken *string `json:"clientToken,omitempty"` RegionID *string `json:"regionID,omitempty"` IDs *string `json:"IDs,omitempty"` @@ -13,17 +13,17 @@ type ListCertificateRequest struct { Type *string `json:"type,omitempty"` } -type ListCertificateResponse struct { +type ListCertificatesResponse struct { baseResult ReturnObj []*CertificateRecord `json:"returnObj,omitempty"` } -func (c *Client) ListCertificate(req *ListCertificateRequest) (*ListCertificateResponse, error) { - return c.ListCertificateWithContext(context.Background(), req) +func (c *Client) ListCertificates(req *ListCertificatesRequest) (*ListCertificatesResponse, error) { + return c.ListCertificatesWithContext(context.Background(), req) } -func (c *Client) ListCertificateWithContext(ctx context.Context, req *ListCertificateRequest) (*ListCertificateResponse, error) { +func (c *Client) ListCertificatesWithContext(ctx context.Context, req *ListCertificatesRequest) (*ListCertificatesResponse, error) { httpreq, err := c.newRequest(http.MethodGet, "/v4/elb/list-certificate") if err != nil { return nil, err @@ -47,7 +47,7 @@ func (c *Client) ListCertificateWithContext(ctx context.Context, req *ListCertif httpreq.SetContext(ctx) } - result := &ListCertificateResponse{} + result := &ListCertificatesResponse{} if _, err := c.doRequestWithResult(httpreq, result); err != nil { return result, err } diff --git a/internal/pkg/sdk3rd/ctyun/elb/api_list_listener.go b/internal/pkg/sdk3rd/ctyun/elb/api_list_listeners.go similarity index 78% rename from internal/pkg/sdk3rd/ctyun/elb/api_list_listener.go rename to internal/pkg/sdk3rd/ctyun/elb/api_list_listeners.go index fe37deaa..404c4399 100644 --- a/internal/pkg/sdk3rd/ctyun/elb/api_list_listener.go +++ b/internal/pkg/sdk3rd/ctyun/elb/api_list_listeners.go @@ -5,7 +5,7 @@ import ( "net/http" ) -type ListListenerRequest struct { +type ListListenersRequest struct { ClientToken *string `json:"clientToken,omitempty"` RegionID *string `json:"regionID,omitempty"` ProjectID *string `json:"projectID,omitempty"` @@ -15,17 +15,17 @@ type ListListenerRequest struct { AccessControlID *string `json:"accessControlID,omitempty"` } -type ListListenerResponse struct { +type ListListenersResponse struct { baseResult ReturnObj []*ListenerRecord `json:"returnObj,omitempty"` } -func (c *Client) ListListener(req *ListListenerRequest) (*ListListenerResponse, error) { - return c.ListListenerWithContext(context.Background(), req) +func (c *Client) ListListeners(req *ListListenersRequest) (*ListListenersResponse, error) { + return c.ListListenersWithContext(context.Background(), req) } -func (c *Client) ListListenerWithContext(ctx context.Context, req *ListListenerRequest) (*ListListenerResponse, error) { +func (c *Client) ListListenersWithContext(ctx context.Context, req *ListListenersRequest) (*ListListenersResponse, error) { httpreq, err := c.newRequest(http.MethodGet, "/v4/elb/list-listener") if err != nil { return nil, err @@ -55,7 +55,7 @@ func (c *Client) ListListenerWithContext(ctx context.Context, req *ListListenerR httpreq.SetContext(ctx) } - result := &ListListenerResponse{} + result := &ListListenersResponse{} if _, err := c.doRequestWithResult(httpreq, result); err != nil { return result, err }