Compare commits

..

3 Commits

Author SHA1 Message Date
ayflying
ed9b0dd248 日志上传批量上传接口修改 2025-07-02 14:52:57 +08:00
ayflying
02edbdae8d 修改config模板的导入方法 2025-06-13 11:14:30 +08:00
ayflying
5e75094c16 s3使用自动模式 2025-06-11 19:11:50 +08:00
3 changed files with 39 additions and 21 deletions

View File

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

View File

@@ -12,6 +12,7 @@ import (
"github.com/elastic/go-elasticsearch/v8/typedapi/types" "github.com/elastic/go-elasticsearch/v8/typedapi/types"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx" "github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/util/gconv"
) )
var ( var (
@@ -23,6 +24,13 @@ type Elastic struct {
name string name string
} }
type elkBulk struct {
Index struct {
Index string `json:"_index"`
Id string `json:"_id"`
} `json:"index"`
}
func NewV1(name string) *Elastic { func NewV1(name string) *Elastic {
var cfg elasticsearch.Config var cfg elasticsearch.Config
_cfg := g.Cfg().MustGetWithEnv(gctx.New(), "elasticsearch") _cfg := g.Cfg().MustGetWithEnv(gctx.New(), "elasticsearch")
@@ -52,7 +60,7 @@ func NewV1(name string) *Elastic {
// fmt.Printf("index:%#v\n", resp.Index) // fmt.Printf("index:%#v\n", resp.Index)
//} //}
// Set 索引文档 // Set 添加文档索引文档
func (s *Elastic) Set(ctx context.Context, key string, data interface{}) (err error) { func (s *Elastic) Set(ctx context.Context, key string, data interface{}) (err error) {
// 添加文档 // 添加文档
_, err = s.client.Index(s.name).Id(key).Document(data).Do(ctx) _, err = s.client.Index(s.name).Id(key).Document(data).Do(ctx)
@@ -61,11 +69,20 @@ func (s *Elastic) Set(ctx context.Context, key string, data interface{}) (err er
// SetBulk 批量添加文档 // SetBulk 批量添加文档
func (s *Elastic) SetBulk(ctx context.Context, data []any) (err error) { func (s *Elastic) SetBulk(ctx context.Context, data []any) (err error) {
var save *bulk.Request var save bulk.Request
save = &bulk.Request{ save = make(bulk.Request, 0)
data, for _, v := range data {
val := gconv.Map(v)
var saveIndex = elkBulk{}
saveIndex.Index.Index = s.name
if _, ok := val["uuid"]; ok {
saveIndex.Index.Id = val["uuid"].(string)
}
save = append(save, saveIndex)
save = append(save, v)
} }
s.client.Bulk().Index(s.name).Request(save).Do(ctx) //save = data
_, err = s.client.Bulk().Index(s.name).Request(&save).Do(ctx)
return return
} }

View File

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