-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (64 loc) · 1.66 KB
/
main.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"log"
"os"
"strconv"
"time"
api "github.com/orted-org/conman/api"
"github.com/orted-org/conman/conman"
)
func main() {
logger := log.Default()
config := conman.NewConfig()
// setting file name
fileName := os.Getenv("CONMAN_FILENAME")
if len(fileName) != 0 {
// file name is specified
config.SetFilename(fileName)
} else {
logger.Println("File not specified")
// no file name is specified
_, err := os.Stat("./temp.json")
if err != nil {
// temp.json not present
logger.Println("Creating temp.json in current directory to store configurations")
_, err := os.Create("./temp.json")
if err != nil {
panic("no file specified and could not create a temp file to store configurations")
}
} else {
// temp.json present
logger.Println("Using temp.json of the current directory for storing configurations")
}
config.SetFilename("./temp.json")
}
config.SetFromFile()
// check if watch file
watchDuration := os.Getenv("CONMAN_WATCH_DURATION")
if len(watchDuration) > 0 {
dur, err := strconv.Atoi(watchDuration)
if err != nil {
panic("error duration set")
}
if dur > 0 {
if len(config.GetFileName()) == 0 {
// duration is passed to watch file but file name not specified
panic("file name not specified to watch")
} else {
config.SetFromFile()
config.WatchFileChanges(time.Second * time.Duration(dur))
}
}
}
secret := os.Getenv("CONMAN_API_SECRET")
if secret == "" {
// using a default api secret
secret = "secret@api"
}
port := os.Getenv("CONMAN_PORT")
if port == "" {
// using the default port as 4000
port = "4000"
}
api.ServerInit(config, secret, "0.0.0.0:"+port)
}