51 lines
1.2 KiB
Go
51 lines
1.2 KiB
Go
|
package dal
|
||
|
|
||
|
import (
|
||
|
"net/url"
|
||
|
"octopus/internal/config"
|
||
|
"sync"
|
||
|
|
||
|
"github.com/minio/minio-go/v7"
|
||
|
"github.com/minio/minio-go/v7/pkg/credentials"
|
||
|
"github.com/rs/zerolog/log"
|
||
|
// pb "github.com/qdrant/go-client/qdrant"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
ossOnce sync.Once
|
||
|
ossInstance *minio.Client
|
||
|
)
|
||
|
|
||
|
func GetMinio() *minio.Client {
|
||
|
ossOnce.Do(initMinio)
|
||
|
return ossInstance
|
||
|
}
|
||
|
|
||
|
func initMinio() {
|
||
|
log.Info().Msg("loading minio configs")
|
||
|
|
||
|
ossConfig, err := url.Parse(config.Get().Databases.OSS)
|
||
|
if err != nil {
|
||
|
log.Fatal().Err(err).Msg("parse oss config error")
|
||
|
}
|
||
|
accessSecret, _ := ossConfig.User.Password()
|
||
|
// defaultConfig := &model.StorageConfig{
|
||
|
// Schema: ossConfig.Scheme,
|
||
|
// Endpoint: ossConfig.Host,
|
||
|
// AccessID: ossConfig.User.Username(),
|
||
|
// AccessSecret: accessSecret,
|
||
|
// Bucket: ossConfig.Query().Get("bucket"),
|
||
|
// Region: ossConfig.Query().Get("region"),
|
||
|
// Secure: cast.ToBool(ossConfig.Query().Get("secure")),
|
||
|
// }
|
||
|
minioClient, err := minio.New(ossConfig.Host, &minio.Options{
|
||
|
Creds: credentials.NewStaticV4(ossConfig.User.Username(), accessSecret, ""),
|
||
|
Secure: false,
|
||
|
})
|
||
|
if err != nil {
|
||
|
log.Fatal().Msgf("minio client init error: %v", err)
|
||
|
}
|
||
|
|
||
|
ossInstance = minioClient
|
||
|
}
|