initial commit
This commit is contained in:
29
file/internal/svc/servicecontext.go
Normal file
29
file/internal/svc/servicecontext.go
Normal file
@ -0,0 +1,29 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"godemo/file/internal/config"
|
||||
"log"
|
||||
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
MinioClient *minio.Client
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
// 初始化 MinIO 客户端
|
||||
minioClient, err := minio.New(c.Minio.Endpoint, &minio.Options{
|
||||
Creds: credentials.NewStaticV4(c.Minio.Id, c.Minio.Secret, c.Minio.Token),
|
||||
Secure: c.Minio.Secure, // 本地部署不用 https
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatalf("failed to initialize minio client: %v", err)
|
||||
}
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
MinioClient: minioClient,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user