-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconfig.go
56 lines (49 loc) · 1.56 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
53
54
55
56
package main
import (
"encoding/json"
"github.com/urfave/cli/v2"
)
type Config struct {
Source string `json:"-"`
LogSocket string `json:"logSocket"`
Locale string `json:"locale"`
SpeakCommand string `json:"speakCommand"`
SpeakLives bool `json:"speakLives"`
SpeakCheers bool `json:"speakCheers"`
ScoreHit string `json:"scoreHits"`
ScoreDamage string `json:"scoreDamages"`
AutoStart bool `json:"autoStart"`
DurationBattle int `json:"durationBattle"`
DurationCountdown int `json:"durationCountdown"`
}
func NewConfigFromContext(cc *cli.Context) (config Config) {
return Config{
Source: cc.String(flagSource),
LogSocket: cc.String(flagLogSocket),
Locale: cc.String(flagLocale),
SpeakCommand: cc.String(flagSpeakCommand),
SpeakCheers: cc.Bool(flagSpeakCheers),
SpeakLives: cc.Bool(flagSpeakLives),
ScoreHit: cc.String(flagScoreHit),
ScoreDamage: cc.String(flagScoreDamage),
AutoStart: cc.Bool(flagAutoStart),
DurationBattle: cc.Int(flagDurationBattle),
DurationCountdown: cc.Int(flagDurationCountdown),
}
}
func NewConfigFromMap(m map[string]interface{}) (config Config, err error) {
bytes, err := json.Marshal(m)
if err != nil {
return
}
config, err = NewConfigFromJSON(bytes)
return
}
func NewConfigFromJSON(data []byte) (config Config, err error) {
err = json.Unmarshal(data, &config)
return
}
func (c Config) ToJSON() (data []byte, err error) {
data, err = json.Marshal(c)
return
}