Ai
64 Star 415 Fork 134

admpub/nging

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
type.go 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
admpub 提交于 2020-05-03 13:54 +08:00 . update
package notice
import (
"fmt"
"io"
"github.com/admpub/log"
"github.com/webx-top/echo/middleware/tplfunc"
)
type (
Noticer func(message interface{}, statusCode int, progress ...*Progress) error
)
var (
// DefaultNoticer 默认noticer
// statusCode > 0 为成功;否则为失败
DefaultNoticer Noticer = func(message interface{}, statusCode int, progs ...*Progress) error {
if len(progs) > 0 && progs[0] != nil {
message = `[ ` + tplfunc.NumberFormat(progs[0].CalcPercent().Percent, 2) + `% ] ` + fmt.Sprint(message)
}
if statusCode > 0 {
log.Info(message)
} else {
log.Error(message)
}
return nil
}
CustomOutputNoticer func(wOut io.Writer, wErr io.Writer) Noticer = func(wOut io.Writer, wErr io.Writer) Noticer {
return func(message interface{}, statusCode int, progs ...*Progress) error {
if len(progs) > 0 && progs[0] != nil {
message = `[ ` + tplfunc.NumberFormat(progs[0].CalcPercent().Percent, 2) + `% ] ` + fmt.Sprint(message)
}
if statusCode > 0 {
fmt.Fprintln(wOut, message)
} else {
fmt.Fprintln(wErr, message)
}
return nil
}
}
)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/admpub/nging.git
git@gitee.com:admpub/nging.git
admpub
nging
nging
v2.2.3

搜索帮助