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
|
package gtagencode
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"maps"
|
"maps"
|
||||||
|
|
||||||
"github.com/foomo/sesamy-go/pkg/encoding/gtag"
|
"github.com/foomo/sesamy-go/pkg/encoding/gtag"
|
||||||
@ -10,18 +11,13 @@ import (
|
|||||||
|
|
||||||
func MPv2(source gtag.Payload, target any) error {
|
func MPv2(source gtag.Payload, target any) error {
|
||||||
var sourceData map[string]any
|
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 {
|
out, err := json.Marshal(source)
|
||||||
return errors.Wrap(err, "failed to decode event")
|
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
|
// transorm map to match mpv2 format
|
||||||
|
|||||||
@ -67,7 +67,7 @@ func TestSelectItem_Pointer(t *testing.T) {
|
|||||||
// fmt.Println(string(out))
|
// fmt.Println(string(out))
|
||||||
// }
|
// }
|
||||||
|
|
||||||
err = mpv2encode.GTag(*intermediate, incoming)
|
err = mpv2encode.GTag(*intermediate, &incoming)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, iso4217.EUR, gtag.Get(incoming.ECommerce.Currency))
|
assert.Equal(t, iso4217.EUR, gtag.Get(incoming.ECommerce.Currency))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user