mirror of
https://github.com/foomo/sesamy-go.git
synced 2025-10-16 12:35:43 +00:00
feat: use json
This commit is contained in:
parent
f021853848
commit
31f2ea9f8f
@ -1,6 +1,7 @@
|
||||
package gtagencode
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"maps"
|
||||
|
||||
"github.com/foomo/sesamy-go/pkg/encoding/gtag"
|
||||
@ -10,18 +11,13 @@ import (
|
||||
|
||||
func MPv2(source gtag.Payload, target any) error {
|
||||
var sourceData map[string]any
|
||||
// encode gtag event to map
|
||||
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
||||
Result: &sourceData,
|
||||
TagName: "json",
|
||||
IgnoreUntaggedFields: true,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to create event decoder")
|
||||
}
|
||||
|
||||
if err := dec.Decode(source); err != nil {
|
||||
return errors.Wrap(err, "failed to decode event")
|
||||
out, err := json.Marshal(source)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to marshal source")
|
||||
}
|
||||
if err = json.Unmarshal(out, &sourceData); err != nil {
|
||||
return errors.Wrap(err, "failed to unmarshal source")
|
||||
}
|
||||
|
||||
// transorm map to match mpv2 format
|
||||
|
||||
@ -67,7 +67,7 @@ func TestSelectItem_Pointer(t *testing.T) {
|
||||
// fmt.Println(string(out))
|
||||
// }
|
||||
|
||||
err = mpv2encode.GTag(*intermediate, incoming)
|
||||
err = mpv2encode.GTag(*intermediate, &incoming)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, iso4217.EUR, gtag.Get(incoming.ECommerce.Currency))
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user