mirror of
https://github.com/foomo/sesamy-go.git
synced 2025-10-16 12:35:43 +00:00
feat: add decode params
This commit is contained in:
parent
d9cee831e8
commit
3bd292ec56
@ -1,5 +1,9 @@
|
||||
package sesamy
|
||||
|
||||
import (
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
type Event[P any] struct {
|
||||
// Reserved names: https://developers.google.com/analytics/devguides/collection/protocol/ga4/reference?client_type=gtag#reserved_names
|
||||
Name EventName `json:"name"`
|
||||
@ -7,6 +11,10 @@ type Event[P any] struct {
|
||||
Params P `json:"params,omitempty"`
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// ~ Constructor
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
func NewEvent[P any](name EventName, params P) Event[P] {
|
||||
return Event[P]{
|
||||
Name: name,
|
||||
@ -14,9 +22,17 @@ func NewEvent[P any](name EventName, params P) Event[P] {
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
// ~ Public methods
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
|
||||
func (e Event[P]) AnyEvent() Event[any] {
|
||||
return Event[any]{
|
||||
Name: e.Name,
|
||||
Params: e.Params,
|
||||
}
|
||||
}
|
||||
|
||||
func (e Event[P]) DecodeParams(output any) error {
|
||||
return mapstructure.Decode(e, output)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user