-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.go
58 lines (46 loc) · 975 Bytes
/
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
package main
import (
"encoding/json"
"fmt"
"os"
)
const ConfigLocation = "./config.json"
type Config struct {
Username string
Password string
BaseUrl string
Quality string
Views string
DownloadLocation string
Token string
TempDirLocation string
NumWorkers int
Slides bool
}
var config Config
func parseConfig(configLocation string) *Config {
var config Config
f, err := os.ReadFile(configLocation)
if err != nil {
fmt.Println("Could not open config file")
panic(err)
}
err = json.Unmarshal(f, &config)
if err != nil {
fmt.Println("Could not parse the config please validate the json")
panic(err)
}
if config.TempDirLocation == "" {
config.TempDirLocation = "./temp"
}
if config.NumWorkers == 0 {
config.NumWorkers = 5
}
return &config
}
func GetConfig() *Config {
if config == (Config{}) {
config = *parseConfig(ConfigLocation)
}
return &config
}