-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.go
More file actions
43 lines (39 loc) · 869 Bytes
/
config.go
File metadata and controls
43 lines (39 loc) · 869 Bytes
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
package main
import (
"encoding/json"
"flag"
"fmt"
"github.com/profawk/espurnaBot/bot"
"os"
)
var config struct {
BotToken string
ChatIds []int64
Watchdog bool
Espurna struct {
Relay int `json:",omitempty"`
Hostname string
ApiKey string
}
Triggers bot.Triggers
}
var filePath = flag.String("c", "config.json", "config file path")
func init() {
flag.Parse()
if _, err := os.Stat(*filePath); os.IsNotExist(err) {
fmt.Println("config file not found")
flag.Usage()
os.Exit(1)
}
f, err := os.Open(*filePath)
if err != nil {
panic(err)
}
if err = json.NewDecoder(f).Decode(&config); err != nil {
panic(err)
}
if config.BotToken == "" || config.Espurna.ApiKey == "" || config.Espurna.Hostname == "" || len(config.ChatIds) == 0 {
panic("json invalid")
}
// if not relay specified 0 should be chosen. done with go zero value
}