1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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"`
- SrmName string `toml:"srmname"`
- SrmPwd string `toml:"srmpwd"`
- }
- 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
- }
|