You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
810 B
Go

package interceptor
import (
ctxpkg "github.com/noahlann/nnet/pkg/context"
)
// Interceptor 拦截器接口
type Interceptor interface {
// Intercept 拦截数据包
// data: 原始数据
// ctx: 上下文
// next: 下一个拦截器
// 返回: 处理后的数据, 是否继续, 错误
Intercept(data []byte, ctx ctxpkg.Context, next Chain) ([]byte, bool, error)
}
// Chain 拦截器链
type Chain interface {
// Next 执行下一个拦截器
Next(data []byte, ctx ctxpkg.Context) ([]byte, bool, error)
}
// HandlerFunc 拦截器函数类型
type HandlerFunc func(data []byte, ctx ctxpkg.Context, next Chain) ([]byte, bool, error)
// Handler 实现Interceptor接口
func (f HandlerFunc) Intercept(data []byte, ctx ctxpkg.Context, next Chain) ([]byte, bool, error) {
return f(data, ctx, next)
}