mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-08-28 00:51:13 +08:00
发布v2.8.4版本,更新内容请查看:https://github.com/bufanyun/hotgo/tree/v2.0/docs/guide-zh-CN/addon-version-upgrade.md
This commit is contained in:
@@ -97,3 +97,14 @@ func IpFilterStrategy(originIp string) (list map[string]struct{}) {
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
// MatchIpStrategy 匹配IP策略,输入ip如果在策略当中返回true
|
||||
func MatchIpStrategy(rules, ip string) bool {
|
||||
allowedIps := IpFilterStrategy(rules)
|
||||
if _, ok := allowedIps["*"]; ok {
|
||||
return true
|
||||
}
|
||||
|
||||
_, ok := allowedIps[ip]
|
||||
return ok
|
||||
}
|
||||
|
@@ -82,20 +82,20 @@ func CheckPassword(input, salt, hash string) (err error) {
|
||||
}
|
||||
|
||||
// SafeGo 安全的调用协程,遇到错误时输出错误日志而不是抛出panic
|
||||
func SafeGo(ctx context.Context, f func(ctx context.Context), level ...interface{}) {
|
||||
var newLevel = glog.LEVEL_ERRO
|
||||
if len(level) > 0 {
|
||||
newLevel = gconv.Int(level[0])
|
||||
func SafeGo(ctx context.Context, f func(ctx context.Context), lv ...interface{}) {
|
||||
var level = glog.LEVEL_ERRO
|
||||
if len(lv) > 0 {
|
||||
level = gconv.Int(lv[0])
|
||||
}
|
||||
|
||||
err := grpool.AddWithRecover(ctx, func(ctx context.Context) {
|
||||
f(ctx)
|
||||
}, func(ctx context.Context, err error) {
|
||||
Logf(newLevel, ctx, "SafeGo exec failed:%+v", err)
|
||||
Logf(level, ctx, "SafeGo exec failed:%+v", err)
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
Logf(newLevel, ctx, "SafeGo AddWithRecover err:%+v", err)
|
||||
Logf(level, ctx, "SafeGo AddWithRecover err:%+v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@@ -3,11 +3,11 @@
|
||||
// @Copyright Copyright (c) 2023 HotGo CLI
|
||||
// @Author Ms <133814250@qq.com>
|
||||
// @License https://github.com/bufanyun/hotgo/blob/master/LICENSE
|
||||
//
|
||||
package validate
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
// Filter 通用过滤器
|
||||
@@ -21,8 +21,12 @@ type Filter interface {
|
||||
|
||||
// PreFilter 预过滤
|
||||
func PreFilter(ctx context.Context, in interface{}) error {
|
||||
if c, ok := in.(Filter); ok {
|
||||
return c.Filter(ctx)
|
||||
}
|
||||
return nil
|
||||
return g.Try(ctx, func(ctx context.Context) {
|
||||
if c, ok := in.(Filter); ok {
|
||||
if err := c.Filter(ctx); err != nil {
|
||||
g.Throw(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user