Exemplo n.º 1
0
func startTango() {
	llog.SetOutput(new(mockResponseWriter))
	llog.SetOutputLevel(llog.Lnone)

	mux := tango.NewWithLog(llog.Std)
	mux.Get("/hello", tangoHandler)
	http.ListenAndServe(":"+strconv.Itoa(port), mux)
}
Exemplo n.º 2
0
Arquivo: conf.go Projeto: jexm/wego
// LoadConfig loads configuration file.
func LoadConfig() *goconfig.ConfigFile {
	var err error

	if fh, _ := os.OpenFile(AppConfPath, os.O_RDONLY|os.O_CREATE, 0600); fh != nil {
		fh.Close()
	}

	// Load configuration, set app version and log level.
	Cfg, err = goconfig.LoadConfigFile(GlobalConfPath)

	if Cfg == nil {
		Cfg, err = goconfig.LoadConfigFile(AppConfPath)
		if err != nil {
			fmt.Println("Fail to load configuration file: " + err.Error())
			os.Exit(2)
		}

	} else {
		Cfg.AppendFiles(AppConfPath)
	}

	Cfg.BlockMode = false

	// set time zone of wetalk system
	TimeZone = Cfg.MustValue("app", "time_zone", "UTC")
	if _, err := time.LoadLocation(TimeZone); err == nil {
		os.Setenv("TZ", TimeZone)
	} else {
		fmt.Println("Wrong time_zone: " + TimeZone + " " + err.Error())
		os.Exit(2)
	}

	// Trim 4th part.
	AppVer = strings.Join(strings.Split(APP_VER, ".")[:3], ".")

	IsProMode = Cfg.MustValue("app", "run_mode") == "pro"

	// cache system
	Cache, err = cache.NewCacher("memory", cache.Options{
		Interval: 360,
	})
	Captcha = captcha.New(captcha.Options{}, Cache)
	Captcha.FieldIdName = "CaptchaId"
	Captcha.FieldCaptchaName = "Captcha"

	// session settings
	SessionProvider = Cfg.MustValue("session", "session_provider", "file")
	SessionSavePath = Cfg.MustValue("session", "session_path", "sessions")
	SessionName = Cfg.MustValue("session", "session_name", "wetalk_sess")
	SessionCookieLifeTime = Cfg.MustInt("session", "session_life_time", 0)
	SessionGCMaxLifetime = Cfg.MustInt64("session", "session_gc_time", 86400)

	EnableXSRF = true
	// xsrf token expire time
	XSRFExpire = 86400 * 365

	DriverName = Cfg.MustValue("orm", "driver_name", "mysql")
	DataSource = Cfg.MustValue("orm", "data_source", "root:@/wetalk?charset=utf8")
	MaxIdle = Cfg.MustInt("orm", "max_idle_conn", 30)
	MaxOpen = Cfg.MustInt("orm", "max_open_conn", 50)
	DebugLog = Cfg.MustBool("orm", "debug_log", false)

	//set logger
	os.MkdirAll("./logs", os.ModePerm)
	f, err := os.Create("logs/wego.log")
	if err != nil {
		log.Panic("create log file failed:", err)
	}

	w := io.MultiWriter(f, os.Stdout)
	log.SetOutput(w)
	Log = log.Std

	if IsProMode {
		log.SetOutputLevel(log.Linfo)
	} else {
		log.SetOutputLevel(log.Ldebug)
	}

	reloadConfig()

	social.DefaultAppUrl = AppUrl

	// OAuth
	var clientId, secret string

	clientId = Cfg.MustValue("oauth", "github_client_id", "your_client_id")
	secret = Cfg.MustValue("oauth", "github_client_secret", "your_client_secret")
	GithubAuth = apps.NewGithub(clientId, secret)

	clientId = Cfg.MustValue("oauth", "google_client_id", "your_client_id")
	secret = Cfg.MustValue("oauth", "google_client_secret", "your_client_secret")
	GoogleAuth = apps.NewGoogle(clientId, secret)

	err = social.RegisterProvider(GithubAuth)
	if err != nil {
		log.Error(err)
	}
	err = social.RegisterProvider(GoogleAuth)
	if err != nil {
		log.Error(err)
	}

	settingLocales()
	settingCompress()

	configWatcher()

	//Qiniu
	ACCESS_KEY = QiniuAccessKey
	SECRET_KEY = QiniuSecurityKey

	return Cfg
}