Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename manifest fields, add example setting #4

Merged
merged 3 commits into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 29 additions & 10 deletions dc_component.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,35 @@ import (
"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 {
// Access settings by using the Slice method
// For example, if you component is setup as following:
// [[components.data_collection]]
// name = "my_component"
// component = "outpout.wasm"
// settings.test_project_id = "123456789"
// settings.test_write_key = "abcdefg"
// Then
// settings.Slice() will return a slice of tuples with the following values:
// [["test_project_id", "123456789"], ["test_write_key", "abcdefg"]]
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)
Expand All @@ -36,9 +49,12 @@ func PageHandler(e dc.Event, settings dc.Dict) dc.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)
Expand All @@ -54,9 +70,12 @@ func TrackHandler(e dc.Event, settings dc.Dict) dc.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)
Expand Down
10 changes: 7 additions & 3 deletions edgee-component.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
manifest_version = 1
manifest-version = 1

[package]
[component]
name = "example-go-component"
version = "1.0.0"
category = "data-collection"
Expand All @@ -10,6 +10,10 @@ documentation = "https://github.com/edgee-cloud/example-go-component"
repository = "https://github.com/edgee-cloud/example-go-component"
wit-world-version = "0.4.0"

[package.build]
[component.build]
command = "go run go.bytecodealliance.org/cmd/wit-bindgen-go generate -o internal/ ./wit && tinygo build -target=wasip2 -o dc_component.wasm --wit-package wit/ --wit-world data-collection ./"
output_path = "./dc_component.wasm"

[component.settings.example]
title = "Example Config Field"
type = "string"