refactor: normalize providers constructors
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/usual2970/certimate/internal/pkg/utils/certs"
|
||||
)
|
||||
|
||||
type AliyunCASUploaderConfig struct {
|
||||
type UploaderConfig struct {
|
||||
// 阿里云 AccessKeyId。
|
||||
AccessKeyId string `json:"accessKeyId"`
|
||||
// 阿里云 AccessKeySecret。
|
||||
@@ -24,14 +24,14 @@ type AliyunCASUploaderConfig struct {
|
||||
Region string `json:"region"`
|
||||
}
|
||||
|
||||
type AliyunCASUploader struct {
|
||||
config *AliyunCASUploaderConfig
|
||||
type UploaderProvider struct {
|
||||
config *UploaderConfig
|
||||
sdkClient *aliyunCas.Client
|
||||
}
|
||||
|
||||
var _ uploader.Uploader = (*AliyunCASUploader)(nil)
|
||||
var _ uploader.Uploader = (*UploaderProvider)(nil)
|
||||
|
||||
func New(config *AliyunCASUploaderConfig) (*AliyunCASUploader, error) {
|
||||
func NewUploader(config *UploaderConfig) (*UploaderProvider, error) {
|
||||
if config == nil {
|
||||
panic("config is nil")
|
||||
}
|
||||
@@ -45,13 +45,13 @@ func New(config *AliyunCASUploaderConfig) (*AliyunCASUploader, error) {
|
||||
return nil, xerrors.Wrap(err, "failed to create sdk client")
|
||||
}
|
||||
|
||||
return &AliyunCASUploader{
|
||||
return &UploaderProvider{
|
||||
config: config,
|
||||
sdkClient: client,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (u *AliyunCASUploader) Upload(ctx context.Context, certPem string, privkeyPem string) (res *uploader.UploadResult, err error) {
|
||||
func (u *UploaderProvider) Upload(ctx context.Context, certPem string, privkeyPem string) (res *uploader.UploadResult, err error) {
|
||||
// 解析证书内容
|
||||
certX509, err := certs.ParseCertificateFromPEM(certPem)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user