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) {
|
|
|
|
case LogContext:
|
|
|
|
eventName = EventNameLog
|
|
|
|
}
|
|
|
|
|
|
|
|
msgEvent := event.NewEvent(eventName)
|
|
|
|
msgEvent.SetValue(MiddleMsgKey, val)
|
|
|
|
middleProduce.Call(ctx, msgEvent)
|
|
|
|
return nil
|
|
|
|
}
|