-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
49 lines (40 loc) · 1.01 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
package main
import (
"os"
"strconv"
)
const (
ServerPortEnv = "Port"
DefaultServerPort = "8080"
ChromiumTimeoutSecondsEnv = "Timeout"
DefaultChromiumTimeoutSeconds = "5000"
EmbededReportUriFmtString = "http://localhost:%d/reports/%s"
)
func getEnv(envName string, defaultValue string) string {
val, ok := os.LookupEnv(envName)
if !ok {
val = defaultValue
}
return val
}
type Config struct {
Port int
ChromiumTimeoutSeconds int
}
func newConfig() Config {
var config = Config{}
var val string
val = getEnv(ServerPortEnv, DefaultServerPort)
port, err := strconv.Atoi(val)
if err != nil || port < 1024 || port > 65535 {
panic(ServerPortEnv + "is not valid")
}
config.Port = port
val = getEnv(ChromiumTimeoutSecondsEnv, DefaultChromiumTimeoutSeconds)
timeout, err := strconv.Atoi(val)
if err != nil || timeout < 1000 || timeout > 10000 {
panic(ChromiumTimeoutSecondsEnv + "is not valid")
}
config.ChromiumTimeoutSeconds = timeout
return config
}