mirror of
https://github.com/hanzoai/insights-go.git
synced 2026-09-30 22:46:12 +00:00
The module declares go 1.27.1 and the adapter image follows. go fix applied the modernizers and left ptrString and ptrBool with no callers, so they are gone; omitzero is not applied, since it changes what the JSON says. Co-authored-by: Hanzo Dev <[email protected]>
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
package insights
|
|
|
|
import "maps"
|
|
|
|
// Properties is used to represent properties in messages that support it.
|
|
// It is a free-form object so the application can set any value it sees fit but
|
|
// a few helper method are defined to make it easier to instantiate properties with
|
|
// common fields.
|
|
// Here's a quick example of how this type is meant to be used:
|
|
//
|
|
// insights.Capture{
|
|
// DistinctId: "0123456789",
|
|
// Properties: insights.NewProperties().
|
|
// Set("revenue", 10.0).
|
|
// Set("currency", "USD"),
|
|
// }
|
|
type Properties map[string]any
|
|
|
|
// NewProperties creates an empty Properties map for fluent construction.
|
|
func NewProperties() Properties {
|
|
return make(Properties, 10)
|
|
}
|
|
|
|
// Set assigns a property value and returns the receiver.
|
|
func (p Properties) Set(name string, value any) Properties {
|
|
p[name] = value
|
|
return p
|
|
}
|
|
|
|
// Merge adds the properties from the provided `props` into the receiver `p`.
|
|
// If a property in `props` already exists in `p`, its value will be overwritten.
|
|
func (p Properties) Merge(props Properties) Properties {
|
|
if props == nil {
|
|
return p
|
|
}
|
|
|
|
maps.Copy(p, props)
|
|
|
|
return p
|
|
}
|