コード例 #1
0
ファイル: server.go プロジェクト: extrame/goblet
func (s *Server) parseConfig() (err error) {
	path := flag.String("config", "./"+s.name+".conf", "设置配置文件的路径")
	for _, plugin := range s.plugins {
		plugin.ParseConfig()
	}
	s.wwwRoot = toml.String("basic.www_root", "./www")
	s.ListenPort = toml.Int("basic.port", 8080)
	s.readTimeOut = toml.Int("basic.read_timeout", 30)
	s.writeTimeOut = toml.Int("basic.write_timeout", 30)
	s.publicDir = toml.String("basic.public_dir", "public")
	s.UploadsDir = toml.String("basic.uploads_dir", "./uploads")
	s.IgnoreUrlCase = toml.Bool("basic.ignore_url_case", true)
	s.HashSecret = toml.String("secret", "cX8Os0wfB6uCGZZSZHIi6rKsy7b0scE9")
	s.env = toml.String("basic.env", config.ProductEnv)
	s.dbEngine = toml.String("basic.db_engine", "mysql")
	s.enDbCache = toml.Bool("cache.enable", false)
	s.cacheAmout = toml.Int("cache.amount", 1000)
	s.logFile = toml.String("log.file", "")
	s.version = toml.String("basic.version", "")
	flag.Parse()
	*path = filepath.FromSlash(*path)
	err = toml.Parse(*path)
	if err == nil {
		s.initLog()
		s.dbHost = toml.String(*s.dbEngine+".host", s.name)
		s.dbUser = toml.String(*s.dbEngine+".user", "")
		s.dbPwd = toml.String(*s.dbEngine+".password", "")
		s.dbName = toml.String(*s.dbEngine+".name", "")
		s.dbPort = toml.Int(*s.dbEngine+".port", 3306)
		s.dbConTO = toml.Int(*s.dbEngine+".connect_timeout", 30)
		s.dbKaInterval = toml.Int(*s.dbEngine+".ka_interval", 0)
		err = toml.Load()
	}
	return
}
コード例 #2
0
ファイル: config.go プロジェクト: extrame/goblet
func (s *Server) AddConfig(name string, obj interface{}) {
	UnmarshalForm(func(tag string) []string {
		pText := toml.String(name+"."+tag, "")
		toml.Load()
		if *pText != "" {
			return []string{*pText}
		} else {
			return []string{}
		}

	}, obj, true)
}