mirror of
https://github.com/foomo/sesamy-go.git
synced 2025-10-16 12:35:43 +00:00
fix: lint errors
This commit is contained in:
parent
d80faf60d8
commit
fbb743cb96
@ -77,7 +77,7 @@ linters:
|
|||||||
- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false]
|
- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false]
|
||||||
- promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false]
|
- promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false]
|
||||||
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false]
|
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false]
|
||||||
- tagliatelle # Checks the struct tags. [fast: true, auto-fix: false]
|
#- tagliatelle # Checks the struct tags. [fast: true, auto-fix: false]
|
||||||
- testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false]
|
- testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false]
|
||||||
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
|
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
|
||||||
- unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false]
|
- unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false]
|
||||||
|
|||||||
@ -1,12 +1,9 @@
|
|||||||
package gtm
|
package gtm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/ThreeDotsLabs/watermill"
|
|
||||||
"github.com/ThreeDotsLabs/watermill/message"
|
"github.com/ThreeDotsLabs/watermill/message"
|
||||||
mpv2 "github.com/foomo/sesamy/measurementprotocol/v2"
|
mpv2 "github.com/foomo/sesamy/measurementprotocol/v2"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -19,7 +16,6 @@ var (
|
|||||||
|
|
||||||
type (
|
type (
|
||||||
Publisher struct {
|
Publisher struct {
|
||||||
//l watermill.LoggerAdapter
|
|
||||||
url string
|
url string
|
||||||
client *http.Client
|
client *http.Client
|
||||||
marshalMessageFunc MarshalMessageFunc
|
marshalMessageFunc MarshalMessageFunc
|
||||||
@ -77,7 +73,6 @@ func (p *Publisher) Publish(topic string, messages ...*message.Message) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, msg := range messages {
|
for _, msg := range messages {
|
||||||
|
|
||||||
var event *mpv2.Event
|
var event *mpv2.Event
|
||||||
if err := json.Unmarshal(msg.Payload, &event); err != nil {
|
if err := json.Unmarshal(msg.Payload, &event); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -88,23 +83,31 @@ func (p *Publisher) Publish(topic string, messages ...*message.Message) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
u := p.url + "?" + values.Encode() + "&richsstsse"
|
var richsstsse bool
|
||||||
|
if values.Has("richsstsse") {
|
||||||
|
values.Del("richsstsse")
|
||||||
|
richsstsse = true
|
||||||
|
}
|
||||||
|
|
||||||
req, err := http.NewRequestWithContext(msg.Context(), "POST", u, body)
|
u := p.url + "?"
|
||||||
|
|
||||||
|
if richsstsse {
|
||||||
|
u += "&richsstsse"
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequestWithContext(msg.Context(), http.MethodPost, u, body)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to create request")
|
||||||
|
}
|
||||||
|
|
||||||
for s, s2 := range msg.Metadata {
|
for s, s2 := range msg.Metadata {
|
||||||
req.Header.Set(s, s2)
|
req.Header.Set(s, s2)
|
||||||
}
|
}
|
||||||
|
|
||||||
//req, err := p.marshalMessageFunc(topic, msg)
|
// logFields := watermill.LogFields{
|
||||||
if err != nil {
|
// "uuid": msg.UUID,
|
||||||
return errors.Wrapf(err, "cannot marshal message %s", msg.UUID)
|
// "provider": ProviderName,
|
||||||
}
|
// }
|
||||||
|
|
||||||
logFields := watermill.LogFields{
|
|
||||||
"uuid": msg.UUID,
|
|
||||||
"provider": ProviderName,
|
|
||||||
}
|
|
||||||
|
|
||||||
// p.l.Trace("Publishing message", logFields)
|
// p.l.Trace("Publishing message", logFields)
|
||||||
|
|
||||||
@ -113,7 +116,7 @@ func (p *Publisher) Publish(topic string, messages ...*message.Message) error {
|
|||||||
return errors.Wrapf(err, "publishing message %s failed", msg.UUID)
|
return errors.Wrapf(err, "publishing message %s failed", msg.UUID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = p.handleResponseBody(resp, logFields); err != nil {
|
if err = p.handleResponseBody(resp); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -140,22 +143,22 @@ func (p *Publisher) Close() error {
|
|||||||
// ~ Private methods
|
// ~ Private methods
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
func (p *Publisher) handleResponseBody(resp *http.Response, logFields watermill.LogFields) error {
|
func (p *Publisher) handleResponseBody(resp *http.Response) error {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode < http.StatusBadRequest {
|
if resp.StatusCode < http.StatusBadRequest {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
// body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
return errors.Wrap(err, "could not read response body")
|
// return errors.Wrap(err, "could not read response body")
|
||||||
}
|
// }
|
||||||
|
|
||||||
logFields = logFields.Add(watermill.LogFields{
|
// logFields = logFields.Add(watermill.LogFields{
|
||||||
"http_status": resp.StatusCode,
|
// "http_status": resp.StatusCode,
|
||||||
"http_response": string(body),
|
// "http_response": string(body),
|
||||||
})
|
// })
|
||||||
// p.l.Info("Server responded with error", logFields)
|
// p.l.Info("Server responded with error", logFields)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -163,17 +166,3 @@ func (p *Publisher) handleResponseBody(resp *http.Response, logFields watermill.
|
|||||||
|
|
||||||
// MarshalMessageFunc transforms the message into a HTTP request to be sent to the specified url.
|
// MarshalMessageFunc transforms the message into a HTTP request to be sent to the specified url.
|
||||||
type MarshalMessageFunc func(url string, msg *message.Message) (*http.Request, error)
|
type MarshalMessageFunc func(url string, msg *message.Message) (*http.Request, error)
|
||||||
|
|
||||||
// DefaultMarshalMessageFunc transforms the message into a HTTP POST request.
|
|
||||||
// It encodes the UUID and Metadata in request headers.
|
|
||||||
func DefaultMarshalMessageFunc(url string, msg *message.Message) (*http.Request, error) {
|
|
||||||
|
|
||||||
req, err := http.NewRequest(http.MethodPost, url, bytes.NewBuffer(msg.Payload))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
req.Header.Set(HeaderUUID, msg.UUID)
|
|
||||||
|
|
||||||
return req, nil
|
|
||||||
}
|
|
||||||
|
|||||||
@ -57,7 +57,6 @@ func (c *Client) HTTPClient() *http.Client {
|
|||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
func (c *Client) Send(ctx context.Context, event *Event) error {
|
func (c *Client) Send(ctx context.Context, event *Event) error {
|
||||||
|
|
||||||
values, body, err := Marshal(event)
|
values, body, err := Marshal(event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to marshall event")
|
return errors.Wrap(err, "failed to marshall event")
|
||||||
@ -90,4 +89,3 @@ func (c *Client) Send(ctx context.Context, event *Event) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -146,7 +146,7 @@ type Event struct {
|
|||||||
// Defines a parameter for the current Event
|
// Defines a parameter for the current Event
|
||||||
// Example: epn.plays_count: 42
|
// Example: epn.plays_count: 42
|
||||||
EventParameterNumber map[string]string `json:"epn,omitempty" mapstructure:"epn,omitempty"`
|
EventParameterNumber map[string]string `json:"epn,omitempty" mapstructure:"epn,omitempty"`
|
||||||
// If the current event is set as a conversion on the admin interace the evfent will have this value present
|
// If the current event is set as a conversion on the admin interacted the evfent will have this value present
|
||||||
// Example: 1
|
// Example: 1
|
||||||
IsConversion *string `json:"_c,omitempty" mapstructure:"_c,omitempty"`
|
IsConversion *string `json:"_c,omitempty" mapstructure:"_c,omitempty"`
|
||||||
// External Event
|
// External Event
|
||||||
@ -181,7 +181,7 @@ type Event struct {
|
|||||||
// If the "_ga_THYNGSTER" cookie last session time value is older than 1800 seconds, the current event will have this value present. This will internally create a new "session_start" event on GA4. If this event is also a conversion the value will be "2" if not, will be "1"
|
// If the "_ga_THYNGSTER" cookie last session time value is older than 1800 seconds, the current event will have this value present. This will internally create a new "session_start" event on GA4. If this event is also a conversion the value will be "2" if not, will be "1"
|
||||||
// Example: 1|2
|
// Example: 1|2
|
||||||
SessionStart *string `json:"_ss,omitempty" mapstructure:"_ss,omitempty"`
|
SessionStart *string `json:"_ss,omitempty" mapstructure:"_ss,omitempty"`
|
||||||
// This seems to be related to the ServerSide hits, it's 0 if the FPLC Cookie is not present and to the current value if it's comming from a Cross Domain linker
|
// This seems to be related to the ServerSide hits, it's 0 if the FPLC Cookie is not present and to the current value if it's coming from a Cross Domain linker
|
||||||
// Example: bVhVicbfiSXaGNxeawKaPlDQc9QXPD6bKcsn36Elden6wZNb7Q5X1iXlkTVP5iP3H3y76cgM3UIgHCaRsYfPoyLGlbiIYMPRjvnUU7KWbdWLagodzxjrlPnvaRZJkw
|
// Example: bVhVicbfiSXaGNxeawKaPlDQc9QXPD6bKcsn36Elden6wZNb7Q5X1iXlkTVP5iP3H3y76cgM3UIgHCaRsYfPoyLGlbiIYMPRjvnUU7KWbdWLagodzxjrlPnvaRZJkw
|
||||||
FirstPartyLinkerCookie *string `json:"_fplc,omitempty" mapstructure:"_fplc,omitempty"`
|
FirstPartyLinkerCookie *string `json:"_fplc,omitempty" mapstructure:"_fplc,omitempty"`
|
||||||
// If the current user has a GA4 session cookie, but not a GA (_ga) client id cookie, this parameter will be added to the hit
|
// If the current user has a GA4 session cookie, but not a GA (_ga) client id cookie, this parameter will be added to the hit
|
||||||
@ -202,7 +202,7 @@ type Event struct {
|
|||||||
// Example: JPY
|
// Example: JPY
|
||||||
Currency *string `json:"cu,omitempty" mapstructure:"cu,omitempty"`
|
Currency *string `json:"cu,omitempty" mapstructure:"cu,omitempty"`
|
||||||
// Example:
|
// Example:
|
||||||
Items []Item `json:"pr,omitempty" mapstructure:"pr,omitempty"`
|
Items []*Item `json:"pr,omitempty" mapstructure:"pr,omitempty"`
|
||||||
// Promotion Impression/Click Tracking. Promotion Id
|
// Promotion Impression/Click Tracking. Promotion Id
|
||||||
// Example: summer-offer
|
// Example: summer-offer
|
||||||
PromotionID *string `json:"pi,omitempty" mapstructure:"pi,omitempty"`
|
PromotionID *string `json:"pi,omitempty" mapstructure:"pi,omitempty"`
|
||||||
@ -211,10 +211,10 @@ type Event struct {
|
|||||||
PromotionName *string `json:"pn,omitempty" mapstructure:"pn,omitempty"`
|
PromotionName *string `json:"pn,omitempty" mapstructure:"pn,omitempty"`
|
||||||
// Promotion Impression/Click Tracking. Creative Name
|
// Promotion Impression/Click Tracking. Creative Name
|
||||||
// Example: red-car
|
// Example: red-car
|
||||||
CreativeName *string `json:"cn,omitempty" mapstructure:"cn,omitempty"`
|
// CreativeName *string `json:"cn,omitempty" mapstructure:"cn,omitempty"`
|
||||||
// Promotion Impression/Click Tracking. Promotion Slot / Position
|
// Promotion Impression/Click Tracking. Promotion Slot / Position
|
||||||
// Example: slide-3
|
// Example: slide-3
|
||||||
CreativeSlot *string `json:"cs,omitempty" mapstructure:"cs,omitempty"`
|
// CreativeSlot *string `json:"cs,omitempty" mapstructure:"cs,omitempty"`
|
||||||
// Google Place ID: Refer to: https://developers.google.com/maps/documentation/places/web-service/place-id . Seems to be inherited from Firebase, not sure about the current use on GA4
|
// Google Place ID: Refer to: https://developers.google.com/maps/documentation/places/web-service/place-id . Seems to be inherited from Firebase, not sure about the current use on GA4
|
||||||
// Example: ChIJiyj437sx3YAR9kUWC8QkLzQ
|
// Example: ChIJiyj437sx3YAR9kUWC8QkLzQ
|
||||||
LocationID *string `json:"lo,omitempty" mapstructure:"lo,omitempty"`
|
LocationID *string `json:"lo,omitempty" mapstructure:"lo,omitempty"`
|
||||||
@ -261,5 +261,3 @@ type Event struct {
|
|||||||
|
|
||||||
Unknown map[string]any `json:"-" mapstructure:",remain"`
|
Unknown map[string]any `json:"-" mapstructure:",remain"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -48,9 +48,9 @@ type AddPaymentInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *AddPaymentInfo) MPv2() *mpv2.Event {
|
func (e *AddPaymentInfo) MPv2() *mpv2.Event {
|
||||||
items := make([]mpv2.Item, len(e.Items))
|
items := make([]*mpv2.Item, len(e.Items))
|
||||||
for i, item := range e.Items {
|
for i, item := range e.Items {
|
||||||
items[i] = *item.MPv2()
|
items[i] = item.MPv2()
|
||||||
}
|
}
|
||||||
return &mpv2.Event{
|
return &mpv2.Event{
|
||||||
Currency: mp.SetString(e.Currency),
|
Currency: mp.SetString(e.Currency),
|
||||||
|
|||||||
@ -48,9 +48,9 @@ type AddShippingInfo struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *AddShippingInfo) MPv2() *mpv2.Event {
|
func (e *AddShippingInfo) MPv2() *mpv2.Event {
|
||||||
items := make([]mpv2.Item, len(e.Items))
|
items := make([]*mpv2.Item, len(e.Items))
|
||||||
for i, item := range e.Items {
|
for i, item := range e.Items {
|
||||||
items[i] = *item.MPv2()
|
items[i] = item.MPv2()
|
||||||
}
|
}
|
||||||
return &mpv2.Event{
|
return &mpv2.Event{
|
||||||
Currency: mp.SetString(e.Currency),
|
Currency: mp.SetString(e.Currency),
|
||||||
|
|||||||
@ -44,9 +44,9 @@ type AddToCart struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *AddToCart) MPv2() *mpv2.Event {
|
func (e *AddToCart) MPv2() *mpv2.Event {
|
||||||
items := make([]mpv2.Item, len(e.Items))
|
items := make([]*mpv2.Item, len(e.Items))
|
||||||
for i, item := range e.Items {
|
for i, item := range e.Items {
|
||||||
items[i] = *item.MPv2()
|
items[i] = item.MPv2()
|
||||||
}
|
}
|
||||||
return &mpv2.Event{
|
return &mpv2.Event{
|
||||||
Currency: mp.SetString(e.Currency),
|
Currency: mp.SetString(e.Currency),
|
||||||
|
|||||||
@ -44,9 +44,9 @@ type AddToWishlist struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *AddToWishlist) MPv2() *mpv2.Event {
|
func (e *AddToWishlist) MPv2() *mpv2.Event {
|
||||||
items := make([]mpv2.Item, len(e.Items))
|
items := make([]*mpv2.Item, len(e.Items))
|
||||||
for i, item := range e.Items {
|
for i, item := range e.Items {
|
||||||
items[i] = *item.MPv2()
|
items[i] = item.MPv2()
|
||||||
}
|
}
|
||||||
return &mpv2.Event{
|
return &mpv2.Event{
|
||||||
Currency: mp.SetString(e.Currency),
|
Currency: mp.SetString(e.Currency),
|
||||||
|
|||||||
@ -46,9 +46,9 @@ type BeginCheckout struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *BeginCheckout) MPv2() *mpv2.Event {
|
func (e *BeginCheckout) MPv2() *mpv2.Event {
|
||||||
items := make([]mpv2.Item, len(e.Items))
|
items := make([]*mpv2.Item, len(e.Items))
|
||||||
for i, item := range e.Items {
|
for i, item := range e.Items {
|
||||||
items[i] = *item.MPv2()
|
items[i] = item.MPv2()
|
||||||
}
|
}
|
||||||
return &mpv2.Event{
|
return &mpv2.Event{
|
||||||
Currency: mp.SetString(e.Currency),
|
Currency: mp.SetString(e.Currency),
|
||||||
|
|||||||
@ -48,13 +48,13 @@ type Purchase struct {
|
|||||||
Coupon string
|
Coupon string
|
||||||
Shipping float64
|
Shipping float64
|
||||||
Tax float64
|
Tax float64
|
||||||
Items []Item
|
Items []*Item
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Purchase) MPv2() *mpv2.Event {
|
func (e *Purchase) MPv2() *mpv2.Event {
|
||||||
items := make([]mpv2.Item, len(e.Items))
|
items := make([]*mpv2.Item, len(e.Items))
|
||||||
for i, item := range e.Items {
|
for i, item := range e.Items {
|
||||||
items[i] = *item.MPv2()
|
items[i] = item.MPv2()
|
||||||
}
|
}
|
||||||
return &mpv2.Event{
|
return &mpv2.Event{
|
||||||
Currency: mp.SetString(e.Currency),
|
Currency: mp.SetString(e.Currency),
|
||||||
|
|||||||
@ -48,13 +48,13 @@ type Refund struct {
|
|||||||
Coupon string
|
Coupon string
|
||||||
Shipping float64
|
Shipping float64
|
||||||
Tax float64
|
Tax float64
|
||||||
Items []Item
|
Items []*Item
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Refund) MPv2() *mpv2.Event {
|
func (e *Refund) MPv2() *mpv2.Event {
|
||||||
items := make([]mpv2.Item, len(e.Items))
|
items := make([]*mpv2.Item, len(e.Items))
|
||||||
for i, item := range e.Items {
|
for i, item := range e.Items {
|
||||||
items[i] = *item.MPv2()
|
items[i] = item.MPv2()
|
||||||
}
|
}
|
||||||
return &mpv2.Event{
|
return &mpv2.Event{
|
||||||
Currency: mp.SetString(e.Currency),
|
Currency: mp.SetString(e.Currency),
|
||||||
|
|||||||
@ -44,9 +44,9 @@ type RemoveFromCart struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *RemoveFromCart) MPv2() *mpv2.Event {
|
func (e *RemoveFromCart) MPv2() *mpv2.Event {
|
||||||
items := make([]mpv2.Item, len(e.Items))
|
items := make([]*mpv2.Item, len(e.Items))
|
||||||
for i, item := range e.Items {
|
for i, item := range e.Items {
|
||||||
items[i] = *item.MPv2()
|
items[i] = item.MPv2()
|
||||||
}
|
}
|
||||||
return &mpv2.Event{
|
return &mpv2.Event{
|
||||||
Currency: mp.SetString(e.Currency),
|
Currency: mp.SetString(e.Currency),
|
||||||
|
|||||||
@ -14,4 +14,3 @@ const (
|
|||||||
func (s EventParameter) String() string {
|
func (s EventParameter) String() string {
|
||||||
return string(s)
|
return string(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,44 +1,47 @@
|
|||||||
package v2
|
package v2
|
||||||
/**
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
|
||||||
promotion_id: "pi",
|
promotion_id: "pi",
|
||||||
promotion_name: "pn",
|
promotion_name: "pn",
|
||||||
creative_name: "cn",
|
creative_name: "cn",
|
||||||
creative_slot: "cs",
|
creative_slot: "cs",
|
||||||
*/
|
*/
|
||||||
type Item struct {
|
type Item struct {
|
||||||
// Exmaple: 12345
|
// Example: 12345
|
||||||
ID *string `json:"id,omitempty" mapstructure:"id,omitempty"`
|
ID *string `json:"id,omitempty" mapstructure:"id,omitempty"`
|
||||||
// Example: Stan and Friends Tee
|
// Example: Stan and Friends Tee
|
||||||
Name *string `json:"nm,omitempty" mapstructure:"nm,omitempty"`
|
Name *string `json:"nm,omitempty" mapstructure:"nm,omitempty"`
|
||||||
// Exmaple: Google
|
// Example: Google
|
||||||
Brand *string `json:"br,omitempty" mapstructure:"br,omitempty"`
|
Brand *string `json:"br,omitempty" mapstructure:"br,omitempty"`
|
||||||
// Exmaple: men
|
// Example: men
|
||||||
CategoryHierarchy1 *string `json:"ca,omitempty" mapstructure:"ca,omitempty"`
|
CategoryHierarchy1 *string `json:"ca,omitempty" mapstructure:"ca,omitempty"`
|
||||||
// Exmaple: t-shirts
|
// Example: t-shirts
|
||||||
CategoryHierarchy2 *string `json:"c2,omitempty" mapstructure:"c2,omitempty"`
|
CategoryHierarchy2 *string `json:"c2,omitempty" mapstructure:"c2,omitempty"`
|
||||||
// Exmaple: men
|
// Example: men
|
||||||
CategoryHierarchy3 *string `json:"c3,omitempty" mapstructure:"c3,omitempty"`
|
CategoryHierarchy3 *string `json:"c3,omitempty" mapstructure:"c3,omitempty"`
|
||||||
// Exmaple: men
|
// Example: men
|
||||||
CategoryHierarchy4 *string `json:"c4,omitempty" mapstructure:"c4,omitempty"`
|
CategoryHierarchy4 *string `json:"c4,omitempty" mapstructure:"c4,omitempty"`
|
||||||
// Exmaple: men
|
// Example: men
|
||||||
CategoryHierarchy5 *string `json:"c5,omitempty" mapstructure:"c5,omitempty"`
|
CategoryHierarchy5 *string `json:"c5,omitempty" mapstructure:"c5,omitempty"`
|
||||||
// Exmaple: Yellow
|
// Example: Yellow
|
||||||
Variant *string `json:"va,omitempty" mapstructure:"va,omitempty"`
|
Variant *string `json:"va,omitempty" mapstructure:"va,omitempty"`
|
||||||
// Exmaple: 123.45
|
// Example: 123.45
|
||||||
Price *string `json:"pr,omitempty" mapstructure:"pr,omitempty"`
|
Price *string `json:"pr,omitempty" mapstructure:"pr,omitempty"`
|
||||||
// Exmaple: 1
|
// Example: 1
|
||||||
Quantity *string `json:"qt,omitempty" mapstructure:"qt,omitempty"`
|
Quantity *string `json:"qt,omitempty" mapstructure:"qt,omitempty"`
|
||||||
// Exmaple: 50%OFF
|
// Example: 50%OFF
|
||||||
Coupon *string `json:"cp,omitempty" mapstructure:"cp,omitempty"`
|
Coupon *string `json:"cp,omitempty" mapstructure:"cp,omitempty"`
|
||||||
// Exmaple: cross-selling: mens
|
// Example: cross-selling: mens
|
||||||
ListName *string `json:"ln,omitempty" mapstructure:"ln,omitempty"`
|
ListName *string `json:"ln,omitempty" mapstructure:"ln,omitempty"`
|
||||||
// Exmaple: 10
|
// Example: 10
|
||||||
ListPosition *string `json:"lp,omitempty" mapstructure:"lp,omitempty"`
|
ListPosition *string `json:"lp,omitempty" mapstructure:"lp,omitempty"`
|
||||||
// Exmaple: id-mens-123
|
// Example: id-mens-123
|
||||||
ListID *string `json:"li,omitempty" mapstructure:"li,omitempty"`
|
ListID *string `json:"li,omitempty" mapstructure:"li,omitempty"`
|
||||||
// Exmaple: 10.00
|
// Example: 10.00
|
||||||
Discount *string `json:"ds,omitempty" mapstructure:"ds,omitempty"`
|
Discount *string `json:"ds,omitempty" mapstructure:"ds,omitempty"`
|
||||||
// Exmaple: Foo Marketplace
|
// Example: Foo Marketplace
|
||||||
Affiliation *string `json:"af,omitempty" mapstructure:"af,omitempty"`
|
Affiliation *string `json:"af,omitempty" mapstructure:"af,omitempty"`
|
||||||
// Example: ChIJIQBpAG2ahYAR_6128GcTUEo
|
// Example: ChIJIQBpAG2ahYAR_6128GcTUEo
|
||||||
LocationID *string `json:"lo,omitempty" mapstructure:"lo,omitempty"`
|
LocationID *string `json:"lo,omitempty" mapstructure:"lo,omitempty"`
|
||||||
|
|||||||
@ -25,7 +25,6 @@ const (
|
|||||||
type Data map[string]any
|
type Data map[string]any
|
||||||
|
|
||||||
func Marshal(input *Event) (url.Values, io.Reader, error) {
|
func Marshal(input *Event) (url.Values, io.Reader, error) {
|
||||||
|
|
||||||
a, err := json.Marshal(input)
|
a, err := json.Marshal(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
@ -81,7 +80,6 @@ func Marshal(input *Event) (url.Values, io.Reader, error) {
|
|||||||
return ret, reader, nil
|
return ret, reader, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func UnmarshalURLValues(input url.Values, output interface{}) error {
|
func UnmarshalURLValues(input url.Values, output interface{}) error {
|
||||||
data := Data{}
|
data := Data{}
|
||||||
|
|
||||||
@ -147,7 +145,7 @@ func DecodeRegexValue(k string, v []string, r *regexp.Regexp, data Data, key str
|
|||||||
v = []map[string]any{}
|
v = []map[string]any{}
|
||||||
}
|
}
|
||||||
v = append(v, value)
|
v = append(v, value)
|
||||||
data[key] = value
|
data[key] = v
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,7 +155,7 @@ func DecodeRegexValue(k string, v []string, r *regexp.Regexp, data Data, key str
|
|||||||
// DecodeObjectValue e.g. `idSKU_123456` = map["id"]="SKU_123456"
|
// DecodeObjectValue e.g. `idSKU_123456` = map["id"]="SKU_123456"
|
||||||
func DecodeObjectValue(s string) (map[string]any, error) {
|
func DecodeObjectValue(s string) (map[string]any, error) {
|
||||||
if len(s) == 0 {
|
if len(s) == 0 {
|
||||||
return nil, nil
|
return nil, nil //nolint:nilnil
|
||||||
}
|
}
|
||||||
ret := map[string]any{}
|
ret := map[string]any{}
|
||||||
for _, part := range strings.Split(s, "~") {
|
for _, part := range strings.Split(s, "~") {
|
||||||
@ -180,7 +178,7 @@ func EncodeObjectValue(s map[string]any) string {
|
|||||||
keys = append(keys, k)
|
keys = append(keys, k)
|
||||||
}
|
}
|
||||||
sort.Strings(keys)
|
sort.Strings(keys)
|
||||||
var ret []string
|
ret := make([]string, 0, len(keys))
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
ret = append(ret, k+fmt.Sprintf("%s", s[k]))
|
ret = append(ret, k+fmt.Sprintf("%s", s[k]))
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
func TestUnmarshalURLValues(t *testing.T) {
|
func TestUnmarshalURLValues(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@ -74,7 +73,6 @@ func TestMarshalURLValues(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestCollect_decodeMapValue(t *testing.T) {
|
func TestCollect_decodeMapValue(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user