-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdc_component.go
91 lines (76 loc) · 2.35 KB
/
dc_component.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main
import (
dc "example-go-component/internal/edgee/protocols/data-collection"
"go.bytecodealliance.org/cm"
)
type Settings struct {
Example string
}
func parseSettings(settings dc.Dict) *Settings {
slice := settings.Slice()
example := ""
for _, v := range slice {
if v[0] == "example" {
example = v[1]
}
}
return &Settings{
Example: example,
}
}
// Implement the datacollection.Exports.Page, datacollection.Exports.Track, and datacollection.Exports.User functions.
// These functions are called by the Edgee runtime to get the HTTP request to make to the provider's API for each event type.
func PageHandler(e dc.Event, settings dc.Dict) dc.EdgeeRequest {
parsedSettings := parseSettings(settings)
headers := [][2]string{
{"Content-Type", "application/json"},
{"Authorization", "Bearer token123"},
{"Example", parsedSettings.Example},
}
list := cm.NewList(&headers[0], len(headers))
dict := dc.Dict(list)
edgeeRequest := dc.EdgeeRequest{
Method: dc.HTTPMethodGET,
URL: "https://example.com/api/resource",
Headers: dict,
Body: `{"key": "value"}`,
ForwardClientHeaders: true,
}
return edgeeRequest
}
func TrackHandler(e dc.Event, settings dc.Dict) dc.EdgeeRequest {
parsedSettings := parseSettings(settings)
headers := [][2]string{
{"Content-Type", "application/json"},
{"Authorization", "Bearer token123"},
{"Example", parsedSettings.Example},
}
list := cm.NewList(&headers[0], len(headers))
dict := dc.Dict(list)
edgeeRequest := dc.EdgeeRequest{
Method: dc.HTTPMethodGET,
URL: "https://example.com/api/resource",
Headers: dict,
Body: `{"key": "value"}`,
ForwardClientHeaders: true,
}
return edgeeRequest
}
func UserHandler(e dc.Event, settings dc.Dict) dc.EdgeeRequest {
parsedSettings := parseSettings(settings)
headers := [][2]string{
{"Content-Type", "application/json"},
{"Authorization", "Bearer token123"},
{"Example", parsedSettings.Example},
}
list := cm.NewList(&headers[0], len(headers))
dict := dc.Dict(list)
edgeeRequest := dc.EdgeeRequest{
Method: dc.HTTPMethodGET,
URL: "https://example.com/api/resource",
Headers: dict,
Body: `{"key": "value"}`,
ForwardClientHeaders: true,
}
return edgeeRequest
}