-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
45 lines (39 loc) · 828 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
package main
import (
"log"
"github.com/Unknwon/goconfig"
)
// Config get conf from file
type Config struct {
URL string
Chapter string
PhpURL string
URLFile string
NovelFile string
StartPage int
}
var config Config
func init() {
config = getConfig("app.conf")
}
func getConfig(filename string) (c Config) {
cfg, err := goconfig.LoadConfigFile(filename)
if err != nil {
log.Fatal(err)
}
baseURL := cfg.MustValue("", "baseurl", "")
chapterIndex := cfg.MustValue("", "chapterindex", "")
phpRequest := cfg.MustValue("", "phprequest", "")
startPage := cfg.MustInt("", "startpage", 2001)
urlFile := cfg.MustValue("", "urlfile", "1.txt")
novelFile := cfg.MustValue("", "novelfile", "2.txt")
c = Config{
baseURL,
chapterIndex,
phpRequest,
urlFile,
novelFile,
startPage,
}
return
}