Merge pull request #86 from jwetzell/feat/struct-get-pointer

allow struct based processors to also operate on pointers to structs
This commit is contained in:
Joel Wetzell
2026-03-08 13:16:08 -05:00
committed by GitHub
4 changed files with 24 additions and 2 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -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 {

View File

@@ -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 {