feat(middle-msg): add SendMiddleMsg function
This commit is contained in:
parent
ec8cea59a4
commit
e2f00fa2ae
|
@ -1,5 +1,34 @@
|
|||
package middle_msg
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitee.com/timedb/wheatCache/pkg/errorx"
|
||||
"gitee.com/timedb/wheatCache/pkg/event"
|
||||
)
|
||||
|
||||
const (
|
||||
MiddleMsgKey = "middleMsgKey"
|
||||
)
|
||||
|
||||
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) {
|
||||
case LogContext:
|
||||
eventName = EventNameLog
|
||||
}
|
||||
|
||||
msgEvent := event.NewEvent(eventName)
|
||||
msgEvent.SetValue(MiddleMsgKey, val)
|
||||
middleProduce.Call(ctx, msgEvent)
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue