-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathruntime.go
More file actions
67 lines (62 loc) · 2.43 KB
/
runtime.go
File metadata and controls
67 lines (62 loc) · 2.43 KB
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
package main
import (
"io"
"os"
"strconv"
"strings"
"encoding/json"
)
type RuntimeInfo struct {
TargetUrl string
HttpMethods []string
HttpHeaders map[string]string
ThreadNum int
TrialNum int
HttpRequestMethodRatio map[string]int
Permanent bool
HttpRequestBody io.Reader
EnableAlert bool
SlackWebHookUrl string
SlackChannel string
SlackNotifyThreshHoldLatencyMillis int
SlackNotifyThreshHoldRps int
}
// NewRuntimeInfo New RuntimeInfo from environment variable
func NewRuntimeInfo() RuntimeInfo {
targetUrl := os.Getenv(EnvTargetUrl)
headers := make(map[string]string)
json.Unmarshal([]byte(os.Getenv(EnvHttpHeaders)), &headers)
threadNum, _ := strconv.Atoi(os.Getenv(EnvThreadNum))
trialNum, _ := strconv.Atoi(os.Getenv(EnvTrialNum))
requestMethodRatio := make(map[string]int)
json.Unmarshal([]byte(os.Getenv(EnvReqHttpMethodRatio)), &requestMethodRatio)
var methods []string
for k := range requestMethodRatio {
methods = append(methods, k)
}
permanent, _ := strconv.ParseBool(os.Getenv(EnvPermanent))
body := strings.NewReader(os.Getenv(EnvHttpRequestBody))
isEnable, _ := strconv.ParseBool(os.Getenv(EnvEnableAlert))
slackWebHookUrl := os.Getenv(EnvSlackWebHookUrl)
slackChannel := os.Getenv(EnvSlackChannel)
if !strings.HasPrefix(slackChannel, "#") {
slackChannel = "#" + slackChannel
}
slackNotifyThreshHoldLatencyMillis, _ := strconv.Atoi(os.Getenv(EnvSlackNotifyThreshHoldLatencyMillis))
slackNotifyThreshHoldRps, _ := strconv.Atoi(os.Getenv(EnvSlackNotifyThreshHoldRps))
return RuntimeInfo{
TargetUrl: targetUrl,
HttpMethods: methods,
HttpHeaders: headers,
ThreadNum: threadNum,
TrialNum: trialNum,
HttpRequestMethodRatio: requestMethodRatio,
Permanent: permanent,
HttpRequestBody: body,
EnableAlert: isEnable,
SlackWebHookUrl: slackWebHookUrl,
SlackChannel: slackChannel,
SlackNotifyThreshHoldLatencyMillis: slackNotifyThreshHoldLatencyMillis,
SlackNotifyThreshHoldRps: slackNotifyThreshHoldRps,
}
}