octopus/pkg/storage/storage.go
2023-03-23 17:44:14 +08:00

45 lines
1.3 KiB
Go

package storage
import (
"errors"
"net/url"
"github.com/spf13/cast"
)
// type ObjectStorage interface {
// // 获取上传对象预签名URL
// PresignedPutObject(ctx context.Context, objectName string, expires time.Duration) (u *url.URL, err error)
// // 获取访问对象预签名URL
// PresignedGetObject(ctx context.Context, objectName string, expires time.Duration) (u *url.URL, err error)
// // 移动对象
// MoveObject(ctx context.Context, src, dst string) error
// // 检查文件是否存在
// ObjectExists(ctx context.Context, objectName string) (bool, error)
// // 获取对象创建时间
// GetObjectCreatedTime(ctx context.Context, objectName string) (time.Time, error)
// }
func NewObjectStorage(dsn string) (*StorageMinio, error) {
u, err := url.Parse(dsn)
if err != nil {
return nil, err
}
user := u.User.Username()
pass, _ := u.User.Password()
switch u.Scheme {
// case "cos":
// ex: cos://examplebucket-1250000000.cos.COS_REGION.myqcloud.com
// return newCosStorage(u.Host, user, pass)
case "minio":
// ex: minio://minio-api:9001?secure=false&bucket=images
secure := cast.ToBool(u.Query().Get("secure"))
bucket := u.Query().Get("bucket")
return newMinioStorage(u.Host, user, pass, secure, bucket)
default:
return nil, errors.New("the storage type not support yet")
}
}