diff --git a/internal/processor/struct-field-get.go b/internal/processor/struct-field-get.go index fa77eb5..46fee69 100644 --- a/internal/processor/struct-field-get.go +++ b/internal/processor/struct-field-get.go @@ -18,7 +18,11 @@ func (sf *StructFieldGet) Process(ctx context.Context, payload any) (any, error) s := reflect.ValueOf(payload) if s.Kind() != reflect.Struct { - return nil, errors.New("struct.field.get processor only accepts a struct payload") + if s.Kind() == reflect.Pointer && s.Elem().Kind() == reflect.Struct { + s = s.Elem() + } else { + return nil, errors.New("struct.field.get processor only accepts a struct payload") + } } field := s.FieldByName(sf.Name) diff --git a/internal/processor/struct-method-get.go b/internal/processor/struct-method-get.go index f6df5a8..2c42e42 100644 --- a/internal/processor/struct-method-get.go +++ b/internal/processor/struct-method-get.go @@ -18,7 +18,11 @@ func (sm *StructMethodGet) Process(ctx context.Context, payload any) (any, error s := reflect.ValueOf(payload) if s.Kind() != reflect.Struct { - return nil, errors.New("struct.method.get processor only accepts a struct payload") + if s.Kind() == reflect.Pointer && s.Elem().Kind() == reflect.Struct { + s = s.Elem() + } else { + return nil, errors.New("struct.method.get processor only accepts a struct payload") + } } method := s.MethodByName(sm.Name) diff --git a/internal/processor/test/struct-field-get_test.go b/internal/processor/test/struct-field-get_test.go index 279046a..5361ba6 100644 --- a/internal/processor/test/struct-field-get_test.go +++ b/internal/processor/test/struct-field-get_test.go @@ -72,6 +72,12 @@ func TestGoodStructFieldGet(t *testing.T) { payload: TestStruct{Bool: true}, expected: true, }, + { + name: "pointer to struct payload", + params: map[string]any{"name": "Data"}, + payload: &TestStruct{Data: "hello"}, + expected: "hello", + }, } for _, test := range tests { diff --git a/internal/processor/test/struct-method-get_test.go b/internal/processor/test/struct-method-get_test.go index 00dbaa1..153ec70 100644 --- a/internal/processor/test/struct-method-get_test.go +++ b/internal/processor/test/struct-method-get_test.go @@ -89,6 +89,14 @@ func TestGoodStructMethodGet(t *testing.T) { payload: TestStruct{}, expected: nil, }, + { + name: "pointer to struct payload", + params: map[string]any{ + "name": "GetData", + }, + payload: &TestStruct{Data: "hello"}, + expected: "hello", + }, } for _, test := range tests {