123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package config
- import (
- "time"
- "github.com/BurntSushi/toml"
- "kpt.xdmy/pkg/log"
- "kpt.xdmy/pkg/setting"
- )
- var (
- confPath string
- Conf = &Config{}
- )
- type Http struct {
- TimeOut time.Duration `toml:"timeout"`
- SapName string `toml:"sapname"`
- SapPwd string `toml:"sappwd"`
- }
- type Config struct {
- DB *MySQLConfig `toml:"db"`
- Http *Http `toml:"http"`
- }
- type MySQLConfig struct {
- DSN string `toml:"dsn"`
- Active int `toml:"active"`
- Idle int `toml:"idle"`
- IdleTimeout time.Duration `toml:"idle_timeout"`
- }
- // func init() {
- // flag.StringVar(&confPath, "tconf", "", "default config path")
- // }
- func Init(p string) (err error) {
- if p != "" {
- confPath = p
- } else {
- confPath, err = setting.GetCurrentPath()
- }
- confPath += "conf/conf.toml"
- if _, err = toml.DecodeFile(confPath, &Conf); err != nil {
- log.Error("config Init : %v", err)
- return
- }
- return
- }
|