-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
113 lines (98 loc) · 1.88 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package config
import (
"os"
"time"
log "github.com/sirupsen/logrus"
"github.com/jinzhu/configor"
_ "github.com/mattn/go-sqlite3" // sqlite3 drivers
)
// Get configs
var Get = loadConfig()
// App config
type App struct {
Activated bool
}
// Command config
type Command struct {
Prefix string
Deactivate []string
}
// Whatsapp config
type Whatsapp struct {
TimeOutDuration time.Duration
SessionPath string
LongClientName string
ShortClientName string
ClientVersion string
RootNumber string
SendBDelay time.Duration
}
// Qrcode config
type Qrcode struct {
FileName string
Quality string
Size uint
GeneratePNG bool
PrintOnCLI bool
}
// Database config
type Database struct {
Path string
SaveBackup bool
BackupPath string
MigrationsPath string
}
// Configuration data
type Configuration struct {
App App
Command Command
Whatsapp Whatsapp
Qrcode Qrcode
Database Database
}
var conf = Configuration{
App: App{
Activated: true,
},
Command: Command{
Prefix: ".",
Deactivate: []string{},
},
Whatsapp: Whatsapp{
TimeOutDuration: 5,
SessionPath: "session",
LongClientName: "Muriboistas",
ShortClientName: "Muriboistas",
ClientVersion: "1.0",
RootNumber: "",
SendBDelay: 180,
},
Qrcode: Qrcode{
FileName: "session",
Quality: "medium",
Size: 256,
GeneratePNG: true,
PrintOnCLI: false,
},
Database: Database{
Path: "data",
SaveBackup: true,
BackupPath: "data/backups",
MigrationsPath: "data/migrations",
},
}
func loadConfig() Configuration {
configFile := "config/config.json"
settings := &configor.Config{
Silent: true,
ENVPrefix: "SB",
}
os.TempDir()
if err := configor.New(settings).Load(&conf, configFile); err != nil {
log.Println(err)
}
if !conf.App.Activated {
log.Fatal("App desactivated!")
}
return conf
}