1 Star 1 Fork 0

linngc / center.gf

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
embedfs.go 1.83 KB
一键复制 编辑 原始数据 按行查看 历史
linngc 提交于 2023-08-08 17:09 . style:struct格式化
// Package embedfs
// @Link https://gitee.com/linngc/center.gf
// @Copyright Copyright (c) 2022 center CLI
// @Author linngc
// @License
package embedfs
import (
"context"
"encoding/json"
"gitee.com/linngc/center.gf/contrib/module/cachebuffer/internal/link"
"gitee.com/linngc/center.gf/contrib/module/cachebuffer/model/marshal"
"github.com/creasty/defaults"
"github.com/gogf/gf/v2/encoding/gyaml"
"github.com/gogf/gf/v2/frame/g"
"net/http"
"sync"
)
var (
todo = context.TODO()
Request = &EmbedFs{}
FileSystem http.FileSystem
initSyncOnce sync.Once
)
type EmbedFs struct {
CosType marshal.CosType `dc:"代理仓库缓存类型"`
position string `dc:"代理仓库对象存储服务存储位置"`
Storage string `yaml:"storage" default:"./storage/embedfs" dc:"本地存储文件路径"`
Bucket string `yaml:"bucket" default:"" dc:"对应的桶名称"`
}
// NewClientV1 存储到本地文件夹客户端管理
func NewClientV1(types marshal.CosType, position string) (client link.ClientV1Interface) {
initSyncOnce.Do(initSync)
Request.CosType = types
Request.position = position
return Request
}
// OnConfig 初始化配置参数信息到内存
func OnConfig(str string) {
// 解析yaml
if err := gyaml.DecodeTo([]byte(str), Request); err != nil {
g.Log().Errorf(todo, "yaml配置文件Unmarshal解析[EmbedFs 存储]出错 %v", err)
return
}
// 添加默认值
if err := defaults.Set(Request); err != nil {
g.Log().Errorf(context.TODO(), "添加[EmbedFs 存储]默认值出错 %v", err)
return
}
//
marshal, _ := json.Marshal(Request)
g.Log().Debugf(context.TODO(), "[EmbedFs 存储]启动参数: %s", marshal)
}
// fileSystemDir 创建资源服务
func initSync() {
//将缓存存储文件夹放入FileSystem,做为资源服务
FileSystem = http.Dir(Request.Storage)
}
Go
1
https://gitee.com/linngc/center.gf.git
git@gitee.com:linngc/center.gf.git
linngc
center.gf
center.gf
52e4a05782b6

搜索帮助