2021-10-16 23:25:34 +08:00
|
|
|
package middlemsg
|
2021-10-09 21:54:26 +08:00
|
|
|
|
2021-10-10 22:26:54 +08:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"gitee.com/timedb/wheatCache/pkg/errorx"
|
|
|
|
"gitee.com/timedb/wheatCache/pkg/event"
|
|
|
|
)
|
|
|
|
|
2021-10-09 21:54:26 +08:00
|
|
|
const (
|
|
|
|
MiddleMsgKey = "middleMsgKey"
|
|
|
|
)
|
2021-10-10 22:26:54 +08:00
|
|
|
|
|
|
|
func SendMiddleMsg(
|
|
|
|
ctx context.Context,
|
|
|
|
middleProduce event.ProduceInterface,
|
|
|
|
val interface{},
|
|
|
|
) error {
|
|
|
|
if middleProduce == nil {
|
|
|
|
return errorx.New("middleProduce not is nil")
|
|
|
|
}
|
|
|
|
|
|
|
|
var eventName string
|
|
|
|
|
|
|
|
switch val.(type) {
|
2021-10-19 15:17:43 +08:00
|
|
|
case *LogContext:
|
|
|
|
eventName = LogContextName
|
|
|
|
case *LruCleanContext:
|
|
|
|
eventName = LruCleanContextName
|
|
|
|
case *LruTTlContext:
|
|
|
|
eventName = LruTTlContextName
|
2021-10-19 16:38:07 +08:00
|
|
|
case *PulginsInfos:
|
|
|
|
eventName = PulginsInfosName
|
2021-10-10 22:26:54 +08:00
|
|
|
}
|
|
|
|
|
2021-10-26 16:01:11 +08:00
|
|
|
msgEvent := middleProduce.NewEvent(eventName)
|
2021-10-10 22:26:54 +08:00
|
|
|
msgEvent.SetValue(MiddleMsgKey, val)
|
|
|
|
middleProduce.Call(ctx, msgEvent)
|
|
|
|
return nil
|
|
|
|
}
|