1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package config
- import (
- "fmt"
- "os"
- "time"
- "github.com/BurntSushi/toml"
- )
- var (
- 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 {
- DB db
- Log log
- Info info
- Alarm alarm
- }
- // Log Config
- type log struct {
- LogPath string
- MaxSize int
- Compress bool
- MaxAge int
- MaxBackups int
- LogLevel string
- Format string
- }
- type db struct {
- MongoP mgo
- Mysql mysql
- Redis redis
- }
- type redis struct {
- Address string
- }
- type mgo struct {
- Addr string
- Dbname string
- Size int
- User string
- Password string
- }
- type mysql struct {
- Addr string
- Dbname string
- Size int
- User string
- Password string
- }
- type duration struct {
- time.Duration
- }
- type info struct {
- ProjectsetIdGt string
- ProjectsetIdLt string
- Ch int //并发
- TableName string //表名 projectset
- Crontab string
- }
- type alarm struct {
- IsOpen bool
- Address string
- Toppic string
- IsJsonEncode bool
- Id string
- Title string
- Text string
- }
- // 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
- }
|