31
internal/storage/client.go
Normal file
31
internal/storage/client.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.apinb.com/ops/files/internal/config"
|
||||
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss"
|
||||
"github.com/aliyun/alibabacloud-oss-go-sdk-v2/oss/credentials"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *oss.Client
|
||||
bucket string
|
||||
publicBaseURL string
|
||||
presignTTL time.Duration
|
||||
}
|
||||
|
||||
func New(cfg config.ObjectStorageConf) (*Client, error) {
|
||||
ossConfig := oss.LoadDefaultConfig().
|
||||
WithRegion(cfg.Region).
|
||||
WithEndpoint(cfg.Endpoint).
|
||||
WithCredentialsProvider(credentials.NewStaticCredentialsProvider(cfg.AccessKeyID, cfg.AccessKeySecret)).
|
||||
WithSignatureVersion(oss.SignatureVersionV4)
|
||||
|
||||
return &Client{
|
||||
client: oss.NewClient(ossConfig),
|
||||
bucket: cfg.Bucket,
|
||||
publicBaseURL: cfg.PublicBaseURL,
|
||||
presignTTL: time.Duration(cfg.PresignTTLSeconds) * time.Second,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user