65 Star 396 Fork 128

admpub/nging

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dbsaver.go 940 Bytes
一键复制 编辑 原始数据 按行查看 历史
admpub 提交于 2020-02-08 20:34 . update
package upload
import (
"io"
uploadClient "github.com/webx-top/client/upload"
"github.com/admpub/color"
"github.com/admpub/log"
modelFile "github.com/admpub/nging/application/model/file"
)
type (
DBSaver func(fileM *modelFile.File, result *uploadClient.Result, reader io.Reader) error
)
var (
dbSavers = map[string]DBSaver{}
DefaultDBSaver = func(fileM *modelFile.File, result *uploadClient.Result, reader io.Reader) error {
return nil
}
)
func DBSaverRegister(key string, dbsaver DBSaver) {
dbSavers[key] = dbsaver
log.Info(color.YellowString(`dbsaver.register:`), key)
}
func DBSaverUnregister(keys ...string) {
for _, key := range keys {
_, ok := dbSavers[key]
if ok {
delete(dbSavers, key)
}
}
}
func DBSaverGet(key string, defaults ...string) DBSaver {
if dbsaver, ok := dbSavers[key]; ok {
return dbsaver
}
if len(defaults) > 0 {
return DBSaverGet(defaults[0])
}
return DefaultDBSaver
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/admpub/nging.git
git@gitee.com:admpub/nging.git
admpub
nging
nging
v2.2.1

搜索帮助