-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconfig.go
52 lines (42 loc) · 1.21 KB
/
config.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
package main
import (
"fmt"
"os"
"time"
"github.com/openfaas/connector-sdk/types"
)
func getControllerConfig() (*types.ControllerConfig, error) {
gURL, ok := os.LookupEnv("gateway_url")
if !ok {
return nil, fmt.Errorf("gateway_url environment variable not set")
}
asynchronousInvocation := false
if val, exists := os.LookupEnv("asynchronous_invocation"); exists {
asynchronousInvocation = (val == "1" || val == "true")
}
contentType := "text/plain"
if v, exists := os.LookupEnv("content_type"); exists && len(v) > 0 {
contentType = v
}
var printResponseBody bool
if val, exists := os.LookupEnv("print_response_body"); exists {
printResponseBody = (val == "1" || val == "true")
}
rebuildInterval := time.Second * 10
if val, exists := os.LookupEnv("rebuild_interval"); exists {
d, err := time.ParseDuration(val)
if err != nil {
return nil, err
}
rebuildInterval = d
}
return &types.ControllerConfig{
RebuildInterval: rebuildInterval,
GatewayURL: gURL,
AsyncFunctionInvocation: asynchronousInvocation,
ContentType: contentType,
PrintResponse: true,
PrintResponseBody: printResponseBody,
PrintRequestBody: false,
}, nil
}