Compare commits

..

2 Commits

Author SHA1 Message Date
ayflying
02edbdae8d 修改config模板的导入方法 2025-06-13 11:14:30 +08:00
ayflying
5e75094c16 s3使用自动模式 2025-06-11 19:11:50 +08:00
2 changed files with 17 additions and 16 deletions

View File

@@ -1,9 +1,9 @@
package config
import (
"github.com/ayflying/utility_go"
"github.com/gogf/gf/v2/util/gutil"
"sync"
"github.com/ayflying/utility_go/pkg"
"github.com/gogf/gf/v2/util/gutil"
"sync"
)
type {cfg}Cfg struct {
@@ -23,7 +23,7 @@ func (c *{mod}Mod) Load(_cfg ...string) {
c.lock.Lock()
defer c.lock.Unlock()
c.cfgArr = make([]*{cfg}Cfg, 0)
data, err := utility_go.Config.GetFile("{file}")
data, err := pkg.Config().GetFile("{file}")
err = data.Scan(&c.cfgArr)
if err != nil {
panic(err)

View File

@@ -63,9 +63,9 @@ func New(_name ...string) *Mod {
obj, err := minio.New(
cfg.Address,
&minio.Options{
Creds: credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, ""),
Secure: cfg.Ssl,
BucketLookup: minio.BucketLookupPath,
Creds: credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, ""),
Secure: cfg.Ssl,
//BucketLookup: minio.BucketLookupPath,
},
)
if err != nil {
@@ -135,9 +135,9 @@ func (s *Mod) ListBuckets() []minio.BucketInfo {
func (s *Mod) PutObject(f io.Reader, name string, bucketName string, _size ...int64) (res minio.UploadInfo, err error) {
// 初始化文件大小为 -1表示将读取文件至结束
var size = int64(-1)
if len(_size) > 0 {
size = _size[0]
}
//if len(_size) > 0 {
// size = _size[0]
//}
// 调用 S3 客户端上传文件,设置内容类型为 "application/octet-stream"
res, err = s.client.PutObject(ctx, bucketName, name, f, size, minio.PutObjectOptions{
//ContentType: "application/octet-stream",
@@ -192,12 +192,13 @@ func (s *Mod) GetUrl(filePath string, defaultFile ...string) (url string) {
filePath = defaultFile[0]
}
switch s.cfg.Provider {
case "qiniu":
url = get + path.Join(bucketName, filePath)
default:
url = get + filePath
}
//switch s.cfg.Provider {
//case "qiniu":
// url = get + path.Join(bucketName, filePath)
//default:
// url = get + filePath
//}
url = get + filePath
if !s.cfg.Ssl {
url = get + path.Join(bucketName, filePath)