1
1
mirror of https://github.com/wader/fq.git synced 2024-12-28 08:02:28 +03:00

Merge pull request #638 from wader/interp-func-decode-value-struct-args

interp: Allow and convert JQValues:s (ex decode value) in function ar…
This commit is contained in:
Mattias Wadman 2023-04-12 12:34:31 +02:00 committed by GitHub
commit 5c69fcc9df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 14 deletions

View File

@ -124,22 +124,11 @@ func CastFn[T any](v any, structFn func(input any, result any) error) (T, bool)
default:
ft := reflect.TypeOf(&t)
if ft.Elem().Kind() == reflect.Struct {
m := map[string]any{}
switch v := v.(type) {
case map[string]any:
m = v
case nil:
// nop use instantiated map
case gojq.JQValue:
if jm, ok := Cast[map[string]any](v.JQValueToGoJQ()); ok {
m = jm
} else {
return t, false
}
default:
// TODO: some way to allow decode value passthru?
m, ok := ToGoJQValue(v)
if !ok {
return t, false
}
if structFn == nil {
panic("structFn nil")
}

View File

@ -262,4 +262,8 @@ mp3> .headers._index
error: expected a extkey but got: _index
mp3> ._index
error: expected a extkey but got: _index
mp3> .headers[0].header.version as $r | {a:12} | tojson({indent: $r}) | println
{
"a": 12
}
mp3> ^D