mirror of
https://github.com/foomo/sesamy-go.git
synced 2025-10-16 12:35:43 +00:00
fix: decode params using json tags
This commit is contained in:
parent
9629047b99
commit
598ab3b8fb
18
pkg/sesamy/decode.go
Normal file
18
pkg/sesamy/decode.go
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package sesamy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/mitchellh/mapstructure"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Decode(input any, output any) error {
|
||||||
|
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
||||||
|
Result: output,
|
||||||
|
TagName: "json",
|
||||||
|
WeaklyTypedInput: true,
|
||||||
|
IgnoreUntaggedFields: true,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return decoder.Decode(input)
|
||||||
|
}
|
||||||
@ -1,9 +1,5 @@
|
|||||||
package sesamy
|
package sesamy
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/mitchellh/mapstructure"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Event[P any] struct {
|
type Event[P any] struct {
|
||||||
// Reserved names: https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference?client_type=gtag#reserved_names
|
// Reserved names: https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference?client_type=gtag#reserved_names
|
||||||
Name EventName `json:"name"`
|
Name EventName `json:"name"`
|
||||||
@ -33,6 +29,10 @@ func (e Event[P]) AnyEvent() Event[any] {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e Event[P]) DecodeParams(output any) error {
|
func (e Event[P]) Decode(output any) error {
|
||||||
return mapstructure.Decode(e, output)
|
return Decode(e, output)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e Event[P]) DecodeParams(output any) error {
|
||||||
|
return Decode(e.Params, output)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user