feat: use json

This commit is contained in:
Kevin Franklin Kim 2024-05-27 14:25:37 +02:00
parent f021853848
commit 31f2ea9f8f
No known key found for this signature in database
2 changed files with 8 additions and 12 deletions

View File

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

View File

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