1 Star 0 Fork 0

蒙蒙的男孩/eosc

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
filter.go 1.27 KB
一键复制 编辑 原始数据 按行查看 历史
蒙蒙的男孩 提交于 2024-01-10 13:49 +08:00 . 重定义项目地址
package eocontext
import "gitee.com/meng_mengs_boys/eosc/utils/config"
var (
FilterSkillName = config.TypeNameOf((*IFilter)(nil))
)
type IFilter interface {
DoFilter(ctx EoContext, next IChain) (err error)
Destroy()
}
type IChain interface {
DoChain(ctx EoContext) error
Destroy()
}
type IChainPro interface {
Destroy()
Chain(ctx EoContext, append ...IFilter) error
}
type Filters []IFilter
func (fs Filters) DoChain(ctx EoContext) error {
if len(fs) > 0 {
f := fs[0]
next := fs[1:]
return f.DoFilter(ctx, next)
}
//ctx.GetComplete().Complete(ctx)
return nil
}
func (fs Filters) Destroy() {
for _, f := range fs {
f.Destroy()
}
}
func DoChain(ctx EoContext, orgfilter Filters, append ...IFilter) error {
fs := orgfilter
fl := len(fs)
al := len(append)
if fl == 0 && al == 0 {
return nil
}
if fl == 0 {
return Filters(append).DoChain(ctx)
}
if al == 0 {
return fs.DoChain(ctx)
}
tp := make(Filters, fl+al)
copy(tp, fs)
copy(tp[fl:], append)
return tp.DoChain(ctx)
}
type _FilterChain struct {
chain IChain
}
func (c *_FilterChain) DoFilter(ctx EoContext, next IChain) (err error) {
return c.chain.DoChain(ctx)
}
func (c *_FilterChain) Destroy() {
c.chain.Destroy()
}
func ToFilter(chain IChain) IFilter {
return &_FilterChain{chain: chain}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/meng_mengs_boys/eosc.git
git@gitee.com:meng_mengs_boys/eosc.git
meng_mengs_boys
eosc
eosc
v1.15.7

搜索帮助