Files
nbi_alarm/core/interceptor/global.go
2023-08-22 19:25:39 +08:00

43 lines
1.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package interceptor
import (
"encoding/hex"
"fmt"
"omc/core/parse"
"time"
"github.com/aceld/zinx/ziface"
)
type GlobalInterceptor struct{}
func (m *GlobalInterceptor) Intercept(chain ziface.IChain) ziface.IcResp {
request := chain.Request() //从责任链中获取当前拦截器的输入数据
// 这一层是自定义拦截器处理逻辑,这里只是简单打印输入
iRequest := request.(ziface.IRequest) //注意由于Zinx的Request类型这里需要做一下断言转换
fmt.Println("\n\n=========自定义拦截器=====")
body, err := parse.RequestBodyDecode(iRequest, nil)
fmt.Printf("消息ID: %v \n", iRequest.GetMsgID())
fmt.Printf("原始数据: %v \n", body.RawData)
fmt.Printf("原始字符: %v \n", hex.EncodeToString(body.RawData))
fmt.Printf("原始字符: %v \n", string(body.RawData))
fmt.Printf("用户ID: %v \n", body.UID)
fmt.Printf("收到消息: %v %v \n", body.Name, body.Data)
fmt.Printf("错误:%v \n", err)
// return chain.Proceed(chain.Request()) //进入并执行下一个拦截器
iMessage := chain.GetIMessage()
resp := chain.ProceedWithIMessage(iMessage, iRequest)
fmt.Printf("目标消息ID: %v \n", iMessage.GetMsgID())
fmt.Printf("收到消息长度: %v \n", iMessage.GetDataLen())
fmt.Printf("信息时间:%v \n", time.Now().String())
fmt.Print("=========自定义拦截器=====\n\n\n")
return resp
}