Exemplo n.º 1
0
func init() {
	setting, err := config.ReadDefault("etfnav.cfg")
	handlerErr(err)

	host, err := setting.String("mysql", "host")
	handlerErr(err)

	port, err := setting.String("mysql", "port")
	handlerErr(err)

	username, err := setting.String("mysql", "username")
	handlerErr(err)

	password, err := setting.String("mysql", "password")
	handlerErr(err)

	WebPort, err = setting.String("web", "port")
	handlerErr(err)

	baseUrlMapping, err := setting.Options("baseurlmapping")
	handlerErr(err)
	BaseUrlMap = make(map[string]string)
	for _, option := range baseUrlMapping {
		baseUrl, err := setting.String("baseurlmapping", option)
		handlerErr(err)

		BaseUrlMap[option] = baseUrl
	}

	tabTextMapping, err := setting.Options("tabtextmapping")
	handlerErr(err)
	TabTextMap = make(map[string][]string)
	for _, option := range tabTextMapping {
		tabText, err := setting.String("tabtextmapping", option)
		handlerErr(err)

		TabTextMap[option] = strings.Split(tabText, "|")
	}

	titleMapping, err := setting.Options("titlemapping")
	handlerErr(err)
	TitleMap = make(map[string][]string)
	for _, option := range titleMapping {
		title, err := setting.String("titlemapping", option)
		handlerErr(err)

		TitleMap[option] = strings.Split(title, "|")
	}

	url := fmt.Sprintf("%v:%v@tcp(%v:%v)/nav_etf?charset=utf8", username, password, host, port)

	db, err = sql.Open("mysql", url)
	handlerErr(err)

	etfWebLogStmt, err = db.Prepare("INSERT INTO etf_web_log (path,client_id,remote_addr,time) VALUES (?,?,?,?);")
	handlerErr(err)
}
Exemplo n.º 2
0
func init() {
	setting, err := config.ReadDefault("config/server.cfg")
	handlerErr(err)

	dbHost, err := setting.String("mysql", "host")
	handlerErr(err)

	dbPort, err := setting.String("mysql", "port")
	handlerErr(err)

	dbUsername, err := setting.String("mysql", "username")
	handlerErr(err)

	dbPassword, err := setting.String("mysql", "password")
	handlerErr(err)

	dbSchema, err := setting.String("mysql", "schema")
	handlerErr(err)

	xmlPathsStr, err := setting.String("osm", "xmlpaths")
	xmlPaths := strings.Split(xmlPathsStr, ",")

	url := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbUsername, dbPassword, dbHost, dbPort, dbSchema)
	Osm, err = osm.NewOsm("mysql", url, xmlPaths)
	if err != nil {
		fmt.Println(err)
	}

	HomeWebPort, err = setting.String("home-web", "port")
	handlerErr(err)

	AdminWebPort, err = setting.String("admin-web", "port")
	handlerErr(err)

	RedisHost, err = setting.String("redis", "host")
	handlerErr(err)

	RedisPort, err = setting.String("redis", "port")
	handlerErr(err)

	appEnv, err := setting.String("app", "env")
	handlerErr(err)

	martini.Env = appEnv

	fmt.Println("home port     : ", HomeWebPort)
	fmt.Println("admin port    : ", AdminWebPort)
	fmt.Println("database info : ", dbHost, dbPort, dbUsername, dbPassword, dbSchema)
	fmt.Println("redis info    : ", RedisHost, RedisPort)
}