Exemplo n.º 1
0
// Loads the config file
func LoadConfig() {
	// Read some flags if set
	//
	// FIXME read these from the config file too
	Config.Verbose = *verbose
	Config.Quiet = *quiet
	Config.ModifyWindow = *modifyWindow
	Config.Checkers = *checkers
	Config.Transfers = *transfers
	Config.DryRun = *dryRun
	Config.Timeout = *timeout
	Config.ConnectTimeout = *connectTimeout
	Config.CheckSum = *checkSum
	Config.SizeOnly = *sizeOnly
	Config.DumpHeaders = *dumpHeaders
	Config.DumpBodies = *dumpBodies

	ConfigPath = *configFile

	// Load configuration file.
	var err error
	ConfigFile, err = goconfig.LoadConfigFile(ConfigPath)
	if err != nil {
		log.Printf("Failed to load config file %v - using defaults: %v", ConfigPath, err)
		ConfigFile, err = goconfig.LoadConfigFile(os.DevNull)
		if err != nil {
			log.Fatalf("Failed to read null config file: %v", err)
		}
	}

	// Start the token bucket limiter
	startTokenBucket()
}
Exemplo n.º 2
0
func SetConfig() {
	var err error
	Cfg, err = cfg.LoadConfigFile("config.ini")
	if err != nil {
		Cfg, err = cfg.LoadConfigFile("../config.ini")
	}
}
Exemplo n.º 3
0
// LoadConfig loads the config file
func LoadConfig() {
	// Read some flags if set
	//
	// FIXME read these from the config file too
	Config.Verbose = *verbose
	Config.Quiet = *quiet
	Config.ModifyWindow = *modifyWindow
	Config.Checkers = *checkers
	Config.Transfers = *transfers
	Config.DryRun = *dryRun
	Config.Timeout = *timeout
	Config.ConnectTimeout = *connectTimeout
	Config.CheckSum = *checkSum
	Config.SizeOnly = *sizeOnly
	Config.IgnoreExisting = *ignoreExisting
	Config.DumpHeaders = *dumpHeaders
	Config.DumpBodies = *dumpBodies
	Config.InsecureSkipVerify = *skipVerify

	ConfigPath = *configFile

	Config.DeleteBefore = *deleteBefore
	Config.DeleteDuring = *deleteDuring
	Config.DeleteAfter = *deleteAfter

	switch {
	case *deleteBefore && (*deleteDuring || *deleteAfter),
		*deleteDuring && *deleteAfter:
		log.Fatalf(`Only one of --delete-before, --delete-during or --delete-after can be used.`)

	// If none are specified, use "during".
	case !*deleteBefore && !*deleteDuring && !*deleteAfter:
		Config.DeleteDuring = true
	}

	// Load configuration file.
	var err error
	ConfigFile, err = goconfig.LoadConfigFile(ConfigPath)
	if err != nil {
		log.Printf("Failed to load config file %v - using defaults: %v", ConfigPath, err)
		ConfigFile, err = goconfig.LoadConfigFile(os.DevNull)
		if err != nil {
			log.Fatalf("Failed to read null config file: %v", err)
		}
	}

	// Load filters
	Config.Filter, err = NewFilter()
	if err != nil {
		log.Fatalf("Failed to load filters: %v", err)
	}

	// Start the token bucket limiter
	startTokenBucket()
}
Exemplo n.º 4
0
func initConfig() {
	var err error
	cfg, err = goconfig.LoadConfigFile(config_file)
	if err != nil {
		log.Fatalf("CANNOT load config file(%s) : %s\n", config_file, err)
	}
	cfg_tunnel, err = goconfig.LoadConfigFile(config_tunnel_file)
	if err != nil {
		log.Fatalf("CANNOT load config file(%s) : %s\n", config_file, err)
	}
}
Exemplo n.º 5
0
func init() {
	if !isExist(_CFG_PATH) {
		os.Create(_CFG_PATH)
	}

	var err error
	Cfg, err = goconfig.LoadConfigFile(_CFG_PATH)
	if err == nil {
		beego.Info("Initialize app.ini")
	}

	setGithubCredentials(Cfg.MustValue("github", "client_id"),
		Cfg.MustValue("github", "client_secret"))

	docLock = new(sync.RWMutex)

	// Load documentation.
	initDocMap()

	// Start check ticker.
	checkTicker = time.NewTicker(5 * time.Minute)
	go checkTickerTimer(checkTicker.C)

	checkDocUpdates()
}
Exemplo n.º 6
0
Arquivo: bango.go Projeto: uu/bango
func LoadBangoConfig(fileName string) {
	var err error
	_, err = os.Stat(fileName)

	if err != nil {
		if os.IsNotExist(err) {
			panic("Configuration file does not exists: " + err.Error())
		} else {
			panic("Something wrong with configuration file: " + err.Error())
		}
	}

	var cfg *goconfig.ConfigFile
	cfg, err = goconfig.LoadConfigFile(fileName)
	if err != nil {
		panic("Fail to load configuration file: " + err.Error())
	}
	// Parse the global section
	config.global.debug = cfg.MustBool("global", "debug", false)

	// Parse the redis section
	config.redis.server = cfg.MustValue("redis", "server", "localhost")
	config.redis.port = cfg.MustValue("redis", "port", "6379")
	config.redis.db = cfg.MustInt("redis", "db", 0)
	config.redis.pass = cfg.MustValue("redis", "pass", "")

	// Parse the fail2ban section
	config.fail2ban.channel = cfg.MustValue("fail2ban", "channel", "fail2ban")
	config.fail2ban.jail = cfg.MustValue("fail2ban", "jail", "fail2ban-recidive")
	config.fail2ban.useF2C = cfg.MustBool("fail2ban", "usef2bclient", true)
}
Exemplo n.º 7
0
func InitModels() {
	if !com.IsFile(_CFG_PATH) {
		os.Create(_CFG_PATH)
	}

	var err error
	Cfg, err = goconfig.LoadConfigFile(_CFG_PATH)
	if err == nil {
		beego.Info("Initialize app.ini")
	}

	setGithubCredentials(Cfg.MustValue("github", "client_id"),
		Cfg.MustValue("github", "client_secret"))

	docLock = new(sync.RWMutex)
	blogLock = new(sync.RWMutex)

	initMaps()

	// Start check ticker.
	checkTicker = time.NewTicker(5 * time.Minute)
	go checkTickerTimer(checkTicker.C)

	// ATTENTION: you'd better comment following code when developing.
	if needCheckUpdate() {
		checkFileUpdates()

		Cfg.SetValue("app", "update_check_time", strconv.Itoa(int(time.Now().Unix())))
		goconfig.SaveConfigFile(Cfg, _CFG_PATH)
	}
}
Exemplo n.º 8
0
//覆盖配置
func CoverConfigByUser() {
	confPath := "conf/conf.ini"
	coverConfs, err := goconfig.LoadConfigFile(confPath)
	if err != nil {
		Waring("Can't find config file:conf/conf.ini ! Use default config.", err.Error())
		return
	}

	if appname, err := coverConfs.GetValue(goconfig.DEFAULT_SECTION, "AppName"); err == nil {
		AppName = appname
	}

	if httpAddress, err := coverConfs.GetValue(goconfig.DEFAULT_SECTION, "HttpAddress"); err == nil {
		HttpAddress = httpAddress
	}

	if httpPort, err := coverConfs.Int(goconfig.DEFAULT_SECTION, "HttpPort"); err == nil {
		HttpPort = httpPort
	}

	if httpServerTimeOut, err := coverConfs.Int64(goconfig.DEFAULT_SECTION, "HttpServerTimeOut"); err == nil {
		HttpServerTimeOut = httpServerTimeOut
	}

	if sessionOn, err := coverConfs.Bool(goconfig.DEFAULT_SECTION, "SessionOn"); err == nil {
		SessionOn = sessionOn
	}
}
Exemplo n.º 9
0
func TestConfig(t *testing.T) {
	config, err := goconfig.LoadConfigFile("chat_conf.ini")
	if err != nil {
		t.Error(err)
	}

	host, err := config.GetValue("redis", "host")
	if err != nil {
		t.Error(err)
	}

	port, err := config.GetValue("redis", "port")
	if err != nil {
		t.Error(err)
	}

	fmt.Println("redis config, host:", host, " port:", port)

	portNum, err := strconv.Atoi(port)
	if err != nil {
		t.Error(err)
	}

	cfg := &redisConfig{host: host, port: portNum}
	fmt.Println("create config obj:", cfg)
	fmt.Println("redis config, host:", cfg.host, " port:", cfg.port)
}
Exemplo n.º 10
0
func init() {
	hd, err := com.HomeDir()
	if err != nil {
		log.Error("", "Fail to get current user")
		log.Fatal("", err.Error())
	}

	HomeDir = strings.Replace(RawHomeDir, "~", hd, -1)

	cfgPath := path.Join(HomeDir, GOPM_CONFIG_FILE)
	if !com.IsExist(cfgPath) {
		os.MkdirAll(path.Dir(cfgPath), os.ModePerm)
		if _, err = os.Create(cfgPath); err != nil {
			log.Error("", "Fail to create gopm config file")
			log.Fatal("", err.Error())
		}
	}
	Cfg, err = goconfig.LoadConfigFile(cfgPath)
	if err != nil {
		log.Error("", "Fail to load gopm config file")
		log.Fatal("", err.Error())
	}

	LoadLocalNodes()
	LoadPkgNameList(path.Join(HomeDir, PKG_NAME_LIST_PATH))
}
Exemplo n.º 11
0
func init() {

	c, err := goconfig.LoadConfigFile("conf/conf.ini")
	if err != nil {
		panic(err)
	}

	driver, err := c.GetValue("Database", "driver")
	if err != nil {
		panic(err)
	}
	dsn, err := c.GetValue("Database", "dsn")

	if err != nil {
		panic(err)
	}

	DataBase, err = xorm.NewEngine(driver, dsn)
	if err != nil {
		panic(err)
	}

	err = DataBase.Ping()
	if err != nil {
		panic(err)
	}
}
Exemplo n.º 12
0
func LoadConfig() (*goconfig.ConfigFile, error) {
	cfg, err := goconfig.LoadConfigFile("gowest.ini")
	if err != nil {
		return nil, err
	}
	return cfg, nil
}
Exemplo n.º 13
0
// LoadConfig loads configuration file.
func LoadConfig(cfgPath string) (*goconfig.ConfigFile, error) {
	if !com.IsExist(cfgPath) {
		os.Create(cfgPath)
	}

	return goconfig.LoadConfigFile(cfgPath)
}
Exemplo n.º 14
0
func (cred *Credentials) FetchFromEnv(path string) {

	// Load config
	cfg, err := goconfig.LoadConfigFile(path)

	// Parse
	clientId, err := cfg.GetValue(goconfig.DEFAULT_SECTION, "id")
	clientSecret, err := cfg.GetValue(goconfig.DEFAULT_SECTION, "secret")

	// Check for errors
	if err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

	// Check for empty values
	if len(clientId) == 0 || len(clientSecret) == 0 {
		log.Fatal("[tesla]: No config found .. ")
		os.Exit(1)
	}

	// Set on Credentials
	cred.ClientId = clientId
	cred.ClientSecret = clientSecret

	// trace
	Ok("[OK] Oauth credentials found")

}
Exemplo n.º 15
0
// LoadConfig loads configuration file.
func LoadConfig(cfgPath string) {
	if !com.IsExist(cfgPath) {
		os.Create(cfgPath)
	}

	var err error
	Cfg, err = goconfig.LoadConfigFile(cfgPath)
	if err != nil {
		log.Fatalf("Fail to load configuration file: %v", err)
	}
	if com.IsFile("custom/app.ini") {
		if err = Cfg.AppendFiles("custom/app.ini"); err != nil {
			log.Fatalf("Fail to load custom configuration file: %v", err)
		}
	}

	DocsJsPath, err = Cfg.GetValue("server", "docs_js_path")
	if err != nil {
		log.Fatalln("Fail to load configuration file: cannot find key docs_js_path")
	}

	HvJsPath, err = Cfg.GetValue("server", "hv_js_path")
	if err != nil {
		log.Fatalln("Fail to load configuration file: cannot find key hv_js_path")
	}
}
Exemplo n.º 16
0
func NewConfigContext() {
	workDir, err := ExecDir()
	if err != nil {
		qlog.Fatalf("Fail to get work directory: %s\n", err)
	}

	cfgPath := filepath.Join(workDir, "conf/app.ini")
	Cfg, err = goconfig.LoadConfigFile(cfgPath)
	if err != nil {
		qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
	}
	Cfg.BlockMode = false

	cfgPaths := []string{os.Getenv("GOGS_CONFIG"), filepath.Join(workDir, "custom/conf/app.ini")}
	for _, cfgPath := range cfgPaths {
		if com.IsFile(cfgPath) {
			if err = Cfg.AppendFiles(cfgPath); err != nil {
				qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
			}
		}
	}

	AppName = Cfg.MustValue("", "APP_NAME", "Gogs: Go Git Service")
	AppLogo = Cfg.MustValue("", "APP_LOGO", "img/favicon.png")
	AppUrl = Cfg.MustValue("server", "ROOT_URL")
	Domain = Cfg.MustValue("server", "DOMAIN")
	OfflineMode = Cfg.MustBool("server", "OFFLINE_MODE", false)
	DisableRouterLog = Cfg.MustBool("server", "DISABLE_ROUTER_LOG", false)
	SecretKey = Cfg.MustValue("security", "SECRET_KEY")

	InstallLock = Cfg.MustBool("security", "INSTALL_LOCK", false)

	RunUser = Cfg.MustValue("", "RUN_USER")
	curUser := os.Getenv("USER")
	if len(curUser) == 0 {
		curUser = os.Getenv("USERNAME")
	}
	// Does not check run user when the install lock is off.
	if InstallLock && RunUser != curUser {
		qlog.Fatalf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
	}

	LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS")
	CookieUserName = Cfg.MustValue("security", "COOKIE_USERNAME")
	CookieRememberName = Cfg.MustValue("security", "COOKIE_REMEMBER_NAME")

	PictureService = Cfg.MustValue("picture", "SERVICE")
	DisableGravatar = Cfg.MustBool("picture", "DISABLE_GRAVATAR", false)

	// Determine and create root git reposiroty path.
	homeDir, err := com.HomeDir()
	if err != nil {
		qlog.Fatalf("Fail to get home directory): %v\n", err)
	}
	RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "gogs-repositories"))
	if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
		qlog.Fatalf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
	}
	ScriptType = Cfg.MustValue("repository", "SCRIPT_TYPE", "bash")
}
Exemplo n.º 17
0
func init() {
	conf, _ := goconfig.LoadConfigFile("./conf/db.ini")
	conf_sq := "local"
	slimmysql.RegisterConnectionDefault(conf.MustBool(conf_sq, "rwseparate"), conf.MustValue(conf_sq, "host"), conf.MustValue(conf_sq, "port"), conf.MustValue(conf_sq, "db"), conf.MustValue(conf_sq, "user"), conf.MustValue(conf_sq, "pass"), conf.MustValue(conf_sq, "prefix"), false)
	conf_sq = "company"
	slimmysql.RegisterConnection("biteabc", conf.MustBool(conf_sq, "rwseparate"), conf.MustValue(conf_sq, "host"), conf.MustValue(conf_sq, "port"), conf.MustValue(conf_sq, "db"), conf.MustValue(conf_sq, "user"), conf.MustValue(conf_sq, "pass"), conf.MustValue(conf_sq, "prefix"), false)
}
Exemplo n.º 18
0
func init() {
	if cfg, err := goconfig.LoadConfigFile("config.ini"); err == nil {
		dbUser, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbuser")
		dbPassword, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbpass")
		dbHost, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbhost")
		dbPort, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbport")
		dbName, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbname")
	} else {
		log.Println("读取配置文件conf.ini失败")
	}

	orm.DefaultTimeLoc = time.Local
	maxIdle := 50  //(可选)  设置最大空闲连接
	maxConn := 100 //(可选)  设置最大数据库连接 (go >= 1.2)
	connStr := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8",
		dbUser,
		dbPassword,
		dbHost,
		dbPort,
		dbName,
	) + "&loc=" + url.QueryEscape("Local")

	if err := orm.RegisterDataBase("default", "mysql",
		connStr,
		maxIdle,
		maxConn,
	); err != nil {
		log.Println(err.Error())
	}

}
Exemplo n.º 19
0
func (this *App) beforeRun() {
	//Session
	if SessionOn {
		confPath := "conf/conf.ini"
		sessConfs, err := goconfig.LoadConfigFile(confPath)
		if err != nil {
			Waring("Can't find config file:conf/conf.ini ! ", err.Error())
			return
		}
		section := "session"
		sessionProvider := sessConfs.MustValue(section, "Provider")
		path := sessConfs.MustValue(section, "Path")
		cookieKey := sessConfs.MustValue(section, "CookieKey")
		domain := sessConfs.MustValue(section, "Domain")
		gcLifeTime := sessConfs.MustInt(section, "GcLifeTime")
		maxLifeTime := sessConfs.MustInt(section, "MaxLifeTime")
		cookieLifeTime := sessConfs.MustInt(section, "CookieLifeTime")
		seesionIdLength := sessConfs.MustInt(section, "SessionIdLength")
		SessionFactory, err = session.NewSessionFactory(sessionProvider, cookieKey, domain, path, gcLifeTime, maxLifeTime, cookieLifeTime, seesionIdLength)
		if err != nil {
			panic("Init session failed." + err.Error())
		}

		// RegisterHookBeforeHttpPre("session", func(ctx *context.Context) {
		// 	var err error
		// 	ctx.Input.Session, err = SessionFactory.SessionStart(ctx.Request, ctx.ResponseWriter)
		// 	if err != nil {
		// 		Error("Session start failed.", err.Error())
		// 	}
		// })

		// RegisterHookAfterHttpFinish("session_save", func(ctx *context.Context) {
		// 	ctx.Input.Session.SessionSave(ctx.ResponseWriter)
		// })
	}

	//view
	err := BuildTpl(ViewPath)
	if err != nil {
		Error("Build template failed,", err.Error())
	}

	//timetask
	for name, t := range tasks {
		if t.runtag == true {
			go t.Start()
			Logger.Info("Timetask:", name, " is running.")
		}
	}

	//hooks
	for key, f := range hooks.hookBeforeAppRun {
		err := f()
		if err != nil {
			Logger.Error("Hook:", key, " err,", err.Error())
		} else {
			Logger.Info("Hook:", key, " finished.")
		}
	}
}
Exemplo n.º 20
0
func CreateIniFile() error {
	f, err := os.OpenFile("./server.ini", os.O_CREATE|os.O_RDWR, 0666)
	if err != nil {
		return err
	}

	defer f.Close()

	config, err = goconfig.LoadConfigFile("./server.ini")
	if err != nil {
		return err
	}

	config.SetSectionComments("App", "")
	config.SetSectionComments("User", "")

	config.SetValue("App", "IP", "127.0.0.1")
	config.SetValue("App", "Port", "8080")
	config.SetValue("User", "username", "admin")
	config.SetValue("User", "password", helper.MD5("admin"))

	err = goconfig.SaveConfigFile(config, "./server.ini")
	if err != nil {
		return err
	}

	return nil
}
Exemplo n.º 21
0
Arquivo: gen.go Projeto: nashtsai/gopm
// scan a directory and gen a gopm file
func runGen(ctx *cli.Context) {
	setup(ctx)

	if !com.IsExist(".gopmfile") {
		os.Create(".gopmfile")
	}

	gf, err := goconfig.LoadConfigFile(".gopmfile")
	if err != nil {
		log.Error("gen", "Cannot load gopmfile:")
		log.Fatal("", "\t"+err.Error())
	}

	// Get dependencies.
	imports := doc.GetAllImports([]string{workDir},
		parseTarget(gf.MustValue("target", "path")), ctx.Bool("example"))

	for _, p := range imports {
		p = doc.GetProjectPath(p)
		if strings.HasSuffix(workDir, p) {
			continue
		}
		if value := gf.MustValue("deps", p); len(value) == 0 {
			gf.SetValue("deps", p, "")
		}
	}

	err = goconfig.SaveConfigFile(gf, ".gopmfile")
	if err != nil {
		log.Error("gen", "Fail to save gopmfile:")
		log.Fatal("", "\t"+err.Error())
	}

	log.Success("SUCC", "gen", "Generate gopmfile successfully!")
}
Exemplo n.º 22
0
func loadConfig(path string) error {

	JCfg = &JFCConfig{}

	c, err := goconfig.LoadConfigFile(path)
	if err != nil {
		return err
	}

	JCfg.JFCPort, err = c.GetValue("Server", "Port")
	if err != nil {
		return err
	}

	JCfg.DbConnString, err = c.GetValue("Database", "DbConnString")
	if err != nil {
		return err
	}
	JCfg.RedisServer, err = c.GetValue("Redis", "Server")
	if err != nil {
		return err
	}
	JCfg.RedisPort, err = c.GetValue("Redis", "Port")
	if err != nil {
		return err
	}
	JCfg.RedisDbIndex, err = c.Int("Redis", "DbIndex")
	if err != nil {
		return err
	}
	return nil
}
Exemplo n.º 23
0
func InitGlobalConfig() error {
	cfg, err := goconfig.LoadConfigFile(CONFIG_FILE_PATH)
	if err != nil {
		return err
	}
	GlobalConfig = &Config{
		TCP_BIND:                 cfg.MustValue(goconfig.DEFAULT_SECTION, "tcp_bind", DEFAULT_TCP_BIND),
		MYSQL_ADDR:               cfg.MustValue(goconfig.DEFAULT_SECTION, "mysql_addr", DEFAULT_MYSQL_ADDR),
		MYSQL_USER:               cfg.MustValue(goconfig.DEFAULT_SECTION, "mysql_user", DEFAULT_MYSQL_USER),
		MYSQL_DBNAME:             cfg.MustValue(goconfig.DEFAULT_SECTION, "mysql_dbname", DEFAULT_MYSQL_DBNAME),
		MYSQL_PASSWORD:           cfg.MustValue(goconfig.DEFAULT_SECTION, "mysql_password", DEFAULT_MYSQL_PASSWORD),
		MYSQL_MAX_CONN:           cfg.MustInt(goconfig.DEFAULT_SECTION, "mysql_max_conn", DEFAULT_MAX_CONN),
		MYSQL_MAX_IDLE_CONN:      cfg.MustInt(goconfig.DEFAULT_SECTION, "mysql_max_idle_conn", DEFAULT_MAX_IDLE_CONN),
		LOG_FILE:                 cfg.MustValue(goconfig.DEFAULT_SECTION, "log_file", "./logs/controller.log", DEFAULT_LOG_FILE),
		LOG_EXPIRE_DAYS:          cfg.MustInt(goconfig.DEFAULT_SECTION, "log_expire_days", DEFAULT_LOG_EXPIRE_DAYS),
		LOG_LEVEL:                cfg.MustInt(goconfig.DEFAULT_SECTION, "log_level", DEFAULT_LOG_LEVEL),
		MAX_PACKET_SIZE:          cfg.MustInt(goconfig.DEFAULT_SECTION, "max_packet_size", DEFAULT_MAX_PACKET_SIZE),
		LOAD_STRATEGIES_INTERVAL: cfg.MustInt(goconfig.DEFAULT_SECTION, "load_strategies_interval", DEFAULT_LOAD_STRATEGIES_INTERVAL),
		TASK_POOL_SIZE:           cfg.MustInt(goconfig.DEFAULT_SECTION, "task_pool_size", DEFAULT_TASK_POOL_SIZE),
		RESULT_POOL_SIZE:         cfg.MustInt(goconfig.DEFAULT_SECTION, "result_pool_size", DEFAULT_RESULT_POOL_SIZE),
		HTTP_SERVER:              cfg.MustValue(goconfig.DEFAULT_SECTION, "http_server", DEFAULT_HTTP_SERVER),
		TASK_SIZE:                cfg.MustInt(goconfig.DEFAULT_SECTION, "task_size", DEFAULT_TASK_SIZE),
		WORKER_COUNT:             cfg.MustInt(goconfig.DEFAULT_SECTION, "worker_count", DEFAULT_WORKER_COUNT),
		ACTION_TIMEOUT:           cfg.MustInt(goconfig.DEFAULT_SECTION, "action_timeout", DEFAULT_ACTION_TIMEOUT),
		SEND_MAIL_SCRIPT:         cfg.MustValue(goconfig.DEFAULT_SECTION, "send_mail_script", DEFAULT_SEND_MAIL_SCRIPT),
		SEND_SMS_SCRIPT:          cfg.MustValue(goconfig.DEFAULT_SECTION, "send_sms_script", DEFAULT_SEND_SMS_SCRIPT),
		SEND_WECHAT_SCRIPT:       cfg.MustValue(goconfig.DEFAULT_SECTION, "send_wechat_script", DEFAULT_SEND_WECHAT_SCRIPT),
	}
	return nil
}
Exemplo n.º 24
0
func (engine *Engine) InitSqlTemplate(options ...SqlTemplateOptions) error {
	var opt SqlTemplateOptions

	if len(options) > 0 {
		opt = options[0]
	}

	if len(opt.Extension) == 0 {
		opt.Extension = ".stpl"
	}
	engine.sqlTemplate.Extension = opt.Extension
	engine.sqlTemplate.Capacity = opt.Capacity

	engine.sqlTemplate.Cipher = opt.Cipher

	var err error
	if engine.sqlTemplate.SqlTemplateRootDir == "" {
		cfg, err := goconfig.LoadConfigFile("./sql/xormcfg.ini")
		if err != nil {
			return err
		}
		engine.sqlTemplate.SqlTemplateRootDir, err = cfg.GetValue("", "SqlTemplateRootDir")
		if err != nil {
			return err
		}
	}

	err = filepath.Walk(engine.sqlTemplate.SqlTemplateRootDir, engine.sqlTemplate.walkFunc)
	if err != nil {
		return err
	}

	return nil
}
Exemplo n.º 25
0
func InitModels() {
	if !com.IsFile(_CFG_PATH) {
		os.Create(_CFG_PATH)
	}

	var err error
	Cfg, err = goconfig.LoadConfigFile(_CFG_PATH)
	if err == nil {
		beego.Info("Initialize app.ini")
	}

	setGithubCredentials(Cfg.MustValue("github", "client_id"),
		Cfg.MustValue("github", "client_secret"))

	docLock = new(sync.RWMutex)

	// Load documentation.
	initDocMap()

	beego.RunMode = Cfg.MustValue("beego", "run_mode")
	// ATTENTION: you'd better comment following code when developing.
	if beego.RunMode == "pro" {
		// Start check ticker.
		checkTicker = time.NewTicker(5 * time.Minute)
		go checkTickerTimer(checkTicker.C)

		checkDocUpdates()
	}
}
Exemplo n.º 26
0
func main() {
	flag.Parse()
	if flag.NArg() == 0 {
		fmt.Println("no args")
		return
	}
	config := flag.Arg(0)

	var err error
	cfg, err = goconfig.LoadConfigFile(config)
	if err != nil {
		fmt.Printf("%s\n", err)
		panic(err)
	}
	retention.TraceFlag = cfg.MustBool(goconfig.DEFAULT_SECTION, "traceFlag")

	dsn, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "dsn")
	sqlstr, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "sql")
	retention.Trace(sqlstr)
	rows, err := mysqldb.GetRows(dsn, sqlstr)
	if err != nil {
		panic(err.Error()) // proper error handling instead of panic in your app
	}

	retention.Trace(rows)
	retention.AnalysisRows(rows)
	retention.Output()
	dsn2, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "dsn2")
	sqlstr2, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "sql2")
	mysqldb.InsertRows(dsn2, sqlstr2, retention.Results())
}
Exemplo n.º 27
0
func main() {
	// make the various backend maps
	proxy = make(map[string]Proxy)
	notFound = make(map[string]NotFound)
	redirect = make(map[string]Redirect)
	static = make(map[string]Static)

	// read all files in the config directory
	files, _ := ioutil.ReadDir(configDir)
	for _, f := range files {
		log.Println("Loading", f.Name())
		cfg, err := goconfig.LoadConfigFile(configDir + "/" + f.Name())
		checkErr(err)
		host, err := cfg.GetValue("DEFAULT", "host")
		if err != nil {
			log.Fatal(err)
		}
		log.Println("host=", host)

		typ, err := cfg.GetValue("DEFAULT", "type")
		if err != nil {
			log.Fatal(err)
		}
		log.Println("type=", typ)

		// depending on the type add it to the right map
		if typ == "NotFound" {
			addNotFound(host)
		}
		if typ == "Proxy" {
			to, err := cfg.GetValue("DEFAULT", "to")
			checkErr(err)
			log.Println("to=", to)
			addProxy(host, to)
		}
		if typ == "Static" {
			dir, err := cfg.GetValue("DEFAULT", "dir")
			checkErr(err)
			log.Println("dir=", dir)
			addStatic(host, dir)
		}
		if typ == "Redirect" {
			to, err := cfg.GetValue("DEFAULT", "to")
			checkErr(err)
			log.Println("to=", to)
			addRedirect(host, to)
		}
	}

	// all setting up of sites done, let's start the server
	log.Println("Starting Server")

	mux := http.NewServeMux()
	mux.HandleFunc("/", Handler)

	err := http.ListenAndServe("localhost:80", mux)
	if err != nil {
		log.Fatal(err)
	}
}
Exemplo n.º 28
0
Arquivo: config.go Projeto: y8y/OWL-v3
func load_config(config_file string) (*Config, error) {
	cfg, err := goconfig.LoadConfigFile(config_file)
	if err != nil {
		return nil, err
	}
	return &Config{
		TCPBIND:     cfg.MustValue(goconfig.DEFAULT_SECTION, "tcp_bind", "0.0.0.0:8888"),
		HTTPBIND:    cfg.MustValue(goconfig.DEFAULT_SECTION, "http_bind", "0.0.0.0:8887"),
		BUFFER_SIZE: cfg.MustInt(goconfig.DEFAULT_SECTION, "buffer_size", 10000),

		MYSQL_BIND:          cfg.MustValue(goconfig.DEFAULT_SECTION, "mysql_bind", "127.0.0.1:3306"),
		MYSQL_USER:          cfg.MustValue(goconfig.DEFAULT_SECTION, "mysql_user", "root"),
		MYSQL_DBNAME:        cfg.MustValue(goconfig.DEFAULT_SECTION, "mysql_dbname", "td_monitor"),
		MYSQL_PASSWORD:      cfg.MustValue(goconfig.DEFAULT_SECTION, "mysql_password", ""),
		MYSQL_MAX_CONN:      cfg.MustInt(goconfig.DEFAULT_SECTION, "mysql_max_conn", 100),
		MYSQL_MAX_IDLE_CONN: cfg.MustInt(goconfig.DEFAULT_SECTION, "mysql_max_idle_conn", 30),
		MAX_PACKET_SIZE:     cfg.MustInt(goconfig.DEFAULT_SECTION, "max_packet_size", 4096),
		LOG_DIR:             cfg.MustValue(goconfig.DEFAULT_SECTION, "log_dir", "./logs"),
		LOG_EXPIRE_DAYS:     cfg.MustInt(goconfig.DEFAULT_SECTION, "log_expire_days", 7),
		LOG_LEVEL:           cfg.MustInt(goconfig.DEFAULT_SECTION, "log_level", 2),

		OPENTSDB_ADDR: cfg.MustValue(goconfig.DEFAULT_SECTION, "opentsdb_addr", "127.0.0.1:4248"),
		ENABLE_REDIS:  cfg.MustBool(goconfig.DEFAULT_SECTION, "enable_redis", false),
		REDIS_ADDR:    cfg.MustValue(goconfig.DEFAULT_SECTION, "redis_addr", "127.0.0.1:6379"),
		REDIS_KEY:     cfg.MustValue(goconfig.DEFAULT_SECTION, "redis_key", "tdmonitor"),
	}, nil

}
Exemplo n.º 29
0
func init() {
	fmt.Println("server Init.")

	runtime.GOMAXPROCS(8)
	memcachep.BindAction(memcachep.GET, GetAction)

	/* 获取配置文件信息 */
	ini, err := goconfig.LoadConfigFile("./scanfile.conf")
	if err != nil {
		panic(err)
	}

	ConfigServerPath, err = ini.GetValue("server", "path")
	if err != nil {
		panic("config not found server.path")
	}

	ConfigServerPort, err = ini.Int("server", "port")
	if err != nil {
		panic("config not found server.port")
	}

	scanfile.MaxResult, err = ini.Int("server", "result_num")
	if err != nil {
		panic("config not found server.result_num")
	}
}
Exemplo n.º 30
0
func main() {
	cfg, err := goconfig.LoadConfigFile("config.ini")
	if err != nil {
		fmt.Println("读取配置文件失败[config.ini]")
		return
	}

	v, _ := cfg.GetValue("Demo", "key1")
	fmt.Println("GetValue: ", v)

	age := cfg.MustInt("parent", "age")
	fmt.Println("MustInt: ", age)

	//借助 Go 语言变参的功能,当 Must 系列方法拥有三个参数时,则第三个参数即为获取失败时的默认值
	age = cfg.MustInt("parent", "age", 100)
	fmt.Println("MustInt and default: ", age)

	money := cfg.MustFloat64("parent", "money", 200)
	fmt.Println("MustFloat64 and default: ", money)

	google, _ := cfg.GetValue(goconfig.DEFAULT_SECTION, "google")
	fmt.Println("default section: ", google)

	vInt, err := cfg.Int("parent", "age")
	if err != nil {
		fmt.Println("Int: ", err)
		return
	}
	fmt.Println("Int: ", vInt)
}