fix: api descript
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"juwan-backend/app/objectstory/rpc/internal/config"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/aws"
|
||||
awsConfig "github.com/aws/aws-sdk-go-v2/config"
|
||||
"github.com/aws/aws-sdk-go-v2/credentials"
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
)
|
||||
|
||||
type ObjectStorageSvc struct {
|
||||
c config.S3ObjectConf
|
||||
}
|
||||
|
||||
func NewObjectStorage(c config.S3ObjectConf) *ObjectStorageSvc {
|
||||
return &ObjectStorageSvc{
|
||||
c: c,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ObjectStorageSvc) MustNews3Client(ctx context.Context) *s3.Client {
|
||||
awsCfg, err := awsConfig.LoadDefaultConfig(ctx,
|
||||
awsConfig.WithRegion(s.c.Region),
|
||||
awsConfig.WithCredentialsProvider(
|
||||
credentials.NewStaticCredentialsProvider(
|
||||
s.c.AccessKey,
|
||||
s.c.SecretKey,
|
||||
"",
|
||||
),
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return s3.NewFromConfig(awsCfg, func(o *s3.Options) {
|
||||
o.BaseEndpoint = aws.String(s.c.Endpoint)
|
||||
o.UsePathStyle = s.c.UsePathStyle
|
||||
})
|
||||
}
|
||||
@@ -1,13 +1,22 @@
|
||||
package svc
|
||||
|
||||
import "juwan-backend/app/objectstory/rpc/internal/config"
|
||||
import (
|
||||
"context"
|
||||
"juwan-backend/app/objectstory/rpc/internal/config"
|
||||
|
||||
"github.com/aws/aws-sdk-go-v2/service/s3"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
S3 *s3.Client
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
s3obj := NewObjectStorage(c.S3Conf)
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
S3: s3obj.MustNews3Client(context.Background()),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user