forked from pnicto/impartus-video-downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
53 lines (42 loc) · 873 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
package main
import (
"encoding/json"
"fmt"
"os"
)
const CONFIG_LOCATION = "./config.json"
type Config struct {
Username string
Password string
BaseUrl string
Quality string
Views string
DownloadLocation string
Token string
TempDirLocation string
Threads int
}
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.Threads < 1 {
config.Threads = 10
}
return &config
}
func GetConfig() *Config {
if config == (Config{}) {
config = *parseConfig(CONFIG_LOCATION)
}
return &config
}