refactor: clean code

This commit is contained in:
Fu Diwei 2024-11-01 15:56:22 +08:00
parent 1dee14e32d
commit 6b5580a30c
6 changed files with 14 additions and 14 deletions

View File

@ -27,7 +27,7 @@ type AliyunCASUploader struct {
}
func New(config *AliyunCASUploaderConfig) (*AliyunCASUploader, error) {
client, err := (&AliyunCASUploader{}).createSdkClient(
client, err := createSdkClient(
config.AccessKeyId,
config.AccessKeySecret,
config.Region,
@ -132,7 +132,7 @@ func (u *AliyunCASUploader) Upload(ctx context.Context, certPem string, privkeyP
}, nil
}
func (u *AliyunCASUploader) createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunCas.Client, error) {
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunCas.Client, error) {
if region == "" {
region = "cn-hangzhou" // CAS 服务默认区域:华东一杭州
}

View File

@ -29,7 +29,7 @@ type AliyunSLBUploader struct {
}
func New(config *AliyunSLBUploaderConfig) (*AliyunSLBUploader, error) {
client, err := (&AliyunSLBUploader{}).createSdkClient(
client, err := createSdkClient(
config.AccessKeyId,
config.AccessKeySecret,
config.Region,
@ -102,7 +102,7 @@ func (u *AliyunSLBUploader) Upload(ctx context.Context, certPem string, privkeyP
}, nil
}
func (u *AliyunSLBUploader) createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunSlb.Client, error) {
func createSdkClient(accessKeyId, accessKeySecret, region string) (*aliyunSlb.Client, error) {
if region == "" {
region = "cn-hangzhou" // SLB 服务默认区域:华东一杭州
}

View File

@ -33,7 +33,7 @@ type HuaweiCloudELBUploader struct {
}
func New(config *HuaweiCloudELBUploaderConfig) (*HuaweiCloudELBUploader, error) {
client, err := (&HuaweiCloudELBUploader{}).createSdkClient(
client, err := createSdkClient(
config.AccessKeyId,
config.SecretAccessKey,
config.Region,
@ -108,7 +108,7 @@ func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, pri
// 获取项目 ID
// REF: https://support.huaweicloud.com/api-iam/iam_06_0001.html
projectId, err := u.getSdkProjectId(u.config.Region, u.config.AccessKeyId, u.config.SecretAccessKey)
projectId, err := getSdkProjectId(u.config.AccessKeyId, u.config.SecretAccessKey, u.config.Region)
if err != nil {
return nil, xerrors.Wrap(err, "failed to get SDK project id")
}
@ -142,7 +142,7 @@ func (u *HuaweiCloudELBUploader) Upload(ctx context.Context, certPem string, pri
}, nil
}
func (u *HuaweiCloudELBUploader) createSdkClient(accessKeyId, secretAccessKey, region string) (*hcElb.ElbClient, error) {
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcElb.ElbClient, error) {
if region == "" {
region = "cn-north-4" // ELB 服务默认区域:华北四北京
}
@ -172,7 +172,7 @@ func (u *HuaweiCloudELBUploader) createSdkClient(accessKeyId, secretAccessKey, r
return client, nil
}
func (u *HuaweiCloudELBUploader) getSdkProjectId(accessKeyId, secretAccessKey, region string) (string, error) {
func getSdkProjectId(accessKeyId, secretAccessKey, region string) (string, error) {
if region == "" {
region = "cn-north-4" // IAM 服务默认区域:华北四北京
}

View File

@ -28,7 +28,7 @@ type HuaweiCloudSCMUploader struct {
}
func New(config *HuaweiCloudSCMUploaderConfig) (*HuaweiCloudSCMUploader, error) {
client, err := (&HuaweiCloudSCMUploader{}).createSdkClient(
client, err := createSdkClient(
config.AccessKeyId,
config.SecretAccessKey,
config.Region,
@ -139,7 +139,7 @@ func (u *HuaweiCloudSCMUploader) Upload(ctx context.Context, certPem string, pri
}, nil
}
func (u *HuaweiCloudSCMUploader) createSdkClient(accessKeyId, secretAccessKey, region string) (*hcScm.ScmClient, error) {
func createSdkClient(accessKeyId, secretAccessKey, region string) (*hcScm.ScmClient, error) {
if region == "" {
region = "cn-north-4" // SCM 服务默认区域:华北四北京
}

View File

@ -24,7 +24,7 @@ type QiniuSSLCertUploader struct {
}
func New(config *QiniuSSLCertUploaderConfig) (*QiniuSSLCertUploader, error) {
client, err := (&QiniuSSLCertUploader{}).createSdkClient(
client, err := createSdkClient(
config.AccessKey,
config.SecretKey,
)
@ -63,7 +63,7 @@ func (u *QiniuSSLCertUploader) Upload(ctx context.Context, certPem string, privk
}, nil
}
func (u *QiniuSSLCertUploader) createSdkClient(accessKey, secretKey string) (*qiniuEx.Client, error) {
func createSdkClient(accessKey, secretKey string) (*qiniuEx.Client, error) {
credential := auth.New(accessKey, secretKey)
client := qiniuEx.NewClient(credential)
return client, nil

View File

@ -22,7 +22,7 @@ type TencentCloudSSLUploader struct {
}
func New(config *TencentCloudSSLUploaderConfig) (*TencentCloudSSLUploader, error) {
client, err := (&TencentCloudSSLUploader{}).createSdkClient(
client, err := createSdkClient(
config.SecretId,
config.SecretKey,
)
@ -55,7 +55,7 @@ func (u *TencentCloudSSLUploader) Upload(ctx context.Context, certPem string, pr
}, nil
}
func (u *TencentCloudSSLUploader) createSdkClient(secretId, secretKey string) (*tcSsl.Client, error) {
func createSdkClient(secretId, secretKey string) (*tcSsl.Client, error) {
credential := common.NewCredential(secretId, secretKey)
client, err := tcSsl.NewClient(credential, "", profile.NewClientProfile())
if err != nil {