forked from kubeshop/xk6-tracetest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apiOptions.go
50 lines (42 loc) · 1002 Bytes
/
apiOptions.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
package models
import (
"fmt"
"github.com/dop251/goja"
"github.com/efischernisc/xk6-tracetest/utils"
"go.k6.io/k6/js/modules"
)
type ApiOptions struct {
ServerUrl string
ServerPath string
APIToken string
}
const (
DefaultServerUrl = "https://app.tracetest.io"
ServerURL = "serverUrl"
ServerPath = "serverPath"
APIToken = "apiToken"
)
func NewApiOptions(vu modules.VU, val goja.Value) (ApiOptions, error) {
rawOptions := utils.ParseOptions(vu, val)
options := ApiOptions{
ServerUrl: DefaultServerUrl,
ServerPath: "",
APIToken: "",
}
if len(rawOptions) == 0 {
return options, nil
}
for key, value := range rawOptions {
switch key {
case ServerURL:
options.ServerUrl = value.ToString().String()
case ServerPath:
options.ServerPath = value.ToString().String()
case APIToken:
options.APIToken = value.ToString().String()
default:
return options, fmt.Errorf("unknown Tracetest option '%s'", key)
}
}
return options, nil
}