-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests.go
49 lines (40 loc) · 1.2 KB
/
requests.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package fullstory
import (
"context"
"encoding/json"
"time"
)
type CreateEventRequest struct {
// Session is the FullStory session to tie this event to
Session Session `json:"session"`
// Context is the event context
Context Context `json:"context"`
// Name is the name of the event
Name string `json:"name"`
// Timestamp is when the event occurred, written out to ISO 8601
Timestamp time.Time `json:"timestamp,omitempty"`
// Properties is the custom event payload (max 20)
Properties map[string]any `json:"properties,omitempty"`
}
func (req *CreateEventRequest) Validate(ctx context.Context) error {
if len(req.Properties) > 20 {
return ErrTooManyProperties
}
return nil
}
func (req *CreateEventRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(struct {
Session Session `json:"session"`
Context Context `json:"context"`
Name string `json:"name"`
Timestamp string `json:"timestamp,omitempty"`
Properties map[string]any `json:"properties,omitempty"`
}{
Session: req.Session,
Context: req.Context,
Name: req.Name,
Timestamp: req.Timestamp.Format(time.RFC3339), // ISO 8601
// TODO: implement schema generation for properties
Properties: req.Properties,
})
}