12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- package config
- import (
- "fmt"
- "os"
- "time"
- "github.com/BurntSushi/toml"
- )
- var (
- // Conf crocodile conf
- Conf *conf
- )
- // Init Config
- func Init(conf string) {
- _, err := toml.DecodeFile(conf, &Conf)
- if err != nil {
- fmt.Printf("Err %v", err)
- os.Exit(1)
- }
- }
- type conf struct {
- Server server
- DB db
- Udp udp
- Mail mail
- Log log
- }
- type server struct {
- Thread int
- ValidTime int
- StatusDays int
- LastId string
- }
- type udp struct {
- LocPort string
- Next udpNext
- }
- type udpNext struct {
- Addr string
- Port int
- Stype string
- }
- type mail struct {
- Send bool
- To string
- Api string
- }
- // Log Config
- type log struct {
- LogPath string
- MaxSize int
- Compress bool
- MaxAge int
- MaxBackups int
- LogLevel string
- Format string
- }
- type db struct {
- MongoB mgo
- MongoP mgo
- }
- type mgo struct {
- Addr string
- Dbname string
- Coll string
- Size int
- User string
- Password string
- }
- type duration struct {
- time.Duration
- }
- // UnmarshalText parse 10s to time.Time
- func (d *duration) UnmarshalText(text []byte) error {
- var err error
- d.Duration, err = time.ParseDuration(string(text))
- return err
- }
|