You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.4 KiB
53 lines
1.4 KiB
package s3
|
|
|
|
import (
|
|
"github.com/aws/aws-sdk-go/aws"
|
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
|
"github.com/aws/aws-sdk-go/aws/session"
|
|
"github.com/aws/aws-sdk-go/service/s3"
|
|
"net/http"
|
|
"wallet-system/internal/conf"
|
|
"wallet-system/internal/pkg/logging/applogger"
|
|
)
|
|
|
|
// S3Client
|
|
// @Description:
|
|
type S3Client struct {
|
|
S3C *s3.S3
|
|
}
|
|
|
|
// NewS3
|
|
//
|
|
// @Description:
|
|
// @param a
|
|
// @return *S3Client
|
|
// @return error
|
|
func NewS3(a *conf.Aws) (*S3Client, error) {
|
|
s := new(S3Client)
|
|
// 创建自定义的 AWS 配置
|
|
awsConfig := &aws.Config{
|
|
Region: aws.String(a.Set.Region), // 设置 AWS 区域
|
|
Credentials: credentials.NewStaticCredentials(
|
|
a.Set.Id, // 替换为您的访问密钥 ID
|
|
a.Set.Secret, // 替换为您的访问密钥
|
|
a.Set.Token), // 提供一个可选的令牌 (token),如果您使用 MFA
|
|
Endpoint: aws.String(a.Link.Point), // 替换为您的自定义别名
|
|
DisableSSL: aws.Bool(false), // 通过 HTTPS 进行连接
|
|
S3ForcePathStyle: aws.Bool(true), // 使用路径样式的 URL
|
|
HTTPClient: &http.Client{}, // 自定义 HTTP 客户端,可选
|
|
}
|
|
|
|
// 创建 AWS 会话
|
|
sess, err := session.NewSession(awsConfig)
|
|
if err != nil {
|
|
applogger.Error("creat Aws-S3 NewSession err:%v", err)
|
|
return nil, err
|
|
}
|
|
|
|
// 创建 S3 服务客户端
|
|
svc := s3.New(sess)
|
|
|
|
s.S3C = svc
|
|
|
|
return s, nil
|
|
}
|
|
|