mirror of
https://github.com/jwetzell/showbridge-go.git
synced 2026-04-27 05:15:47 +00:00
wrap literal payloads into a struct for expr processors
This commit is contained in:
@@ -15,9 +15,29 @@ type FilterExpr struct {
|
||||
Program *vm.Program
|
||||
}
|
||||
|
||||
func (se *FilterExpr) Process(ctx context.Context, payload any) (any, error) {
|
||||
type PayloadStruct struct {
|
||||
Payload any
|
||||
}
|
||||
|
||||
output, err := expr.Run(se.Program, payload)
|
||||
func (se *FilterExpr) Process(ctx context.Context, payload any) (any, error) {
|
||||
payloadType := fmt.Sprintf("%T", payload)
|
||||
|
||||
exprEnv := payload
|
||||
|
||||
switch payloadType {
|
||||
case "uint", "uint8", "uint16", "uint32", "uint64":
|
||||
exprEnv = PayloadStruct{Payload: payload}
|
||||
case "int", "int8", "int16", "int32", "int64":
|
||||
exprEnv = PayloadStruct{Payload: payload}
|
||||
case "float32", "float64":
|
||||
exprEnv = PayloadStruct{Payload: payload}
|
||||
case "string":
|
||||
exprEnv = PayloadStruct{Payload: payload}
|
||||
case "bool":
|
||||
exprEnv = PayloadStruct{Payload: payload}
|
||||
}
|
||||
|
||||
output, err := expr.Run(se.Program, exprEnv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -17,7 +17,24 @@ type ScriptExpr struct {
|
||||
|
||||
func (se *ScriptExpr) Process(ctx context.Context, payload any) (any, error) {
|
||||
|
||||
output, err := expr.Run(se.Program, payload)
|
||||
payloadType := fmt.Sprintf("%T", payload)
|
||||
|
||||
exprEnv := payload
|
||||
|
||||
switch payloadType {
|
||||
case "uint", "uint8", "uint16", "uint32", "uint64":
|
||||
exprEnv = PayloadStruct{Payload: payload}
|
||||
case "int", "int8", "int16", "int32", "int64":
|
||||
exprEnv = PayloadStruct{Payload: payload}
|
||||
case "float32", "float64":
|
||||
exprEnv = PayloadStruct{Payload: payload}
|
||||
case "string":
|
||||
exprEnv = PayloadStruct{Payload: payload}
|
||||
case "bool":
|
||||
exprEnv = PayloadStruct{Payload: payload}
|
||||
}
|
||||
|
||||
output, err := expr.Run(se.Program, exprEnv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user