forked from aQuaYi/LeetCode-in-Go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
49 lines (39 loc) · 764 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
package main
import (
"fmt"
"log"
"github.com/BurntSushi/toml"
)
const (
configTOML = "config.toml"
)
type config struct {
Username string
Password string
Cookie string
// 以下是电子邮件设置
SMTP string
Port int
From string
To string
EmailPassword string
}
func (c config) String() string {
format := "Username: %s, Password: %s, SMTP: %s, Port: %d, From: %s, To: %s, EmailPassword: %s "
return fmt.Sprintf(format,
c.Username,
c.Password,
c.SMTP,
c.Port,
c.From,
c.To,
c.EmailPassword)
}
func getConfig() *config {
cfg := new(config)
if _, err := toml.DecodeFile(configTOML, &cfg); err != nil {
log.Panicf(err.Error())
}
// log.Printf("get config: %s", cfg)
return cfg
}