woj-server/internal/service/storage/service.go

57 lines
1.2 KiB
Go
Raw Normal View History

package storage
import (
2023-07-14 21:47:11 +08:00
"git.0x7f.app/WOJ/woj-server/internal/e"
2023-07-15 16:19:49 +08:00
"git.0x7f.app/WOJ/woj-server/internal/misc/config"
"git.0x7f.app/WOJ/woj-server/internal/misc/log"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
2023-07-15 16:19:49 +08:00
"github.com/samber/do"
"go.uber.org/zap"
"time"
)
var _ Service = (*service)(nil)
type Service interface {
Upload(objectName string, expiry time.Duration) (string, e.Status)
Get(objectName string, expiry time.Duration) (string, e.Status)
2023-07-15 16:19:49 +08:00
HealthCheck() error
}
func NewService(i *do.Injector) (Service, error) {
conf := do.MustInvoke[config.Service](i).GetConfig()
srv := &service{
log: do.MustInvoke[log.Service](i).GetLogger("storage"),
bucket: conf.Storage.Bucket,
}
var err error
srv.client, err = minio.New(
conf.Storage.Endpoint,
&minio.Options{
Creds: credentials.NewStaticV4(conf.Storage.AccessKey, conf.Storage.SecretKey, ""),
Secure: conf.Storage.UseSSL,
},
)
if err != nil {
srv.log.Error("failed to create minio client", zap.Error(err))
return nil, err
}
return srv, nil
}
type service struct {
log *zap.Logger
client *minio.Client
bucket string
}
2023-07-15 16:19:49 +08:00
func (s *service) HealthCheck() error {
return nil
}