Example #1
0
func init() {
	var err error
	if cfg.GetCfg().Debug {
		fmt.Printf("Mongo:%v\n", cfg.GetCfg().MgoURL)
	}
	mgoSession, err = mgo.Dial(cfg.GetCfg().MgoURL)
	panicOnError(err)
}
Example #2
0
func main() {

	go func() {
		err := http.ListenAndServeTLS(cfg.GetCfg().SslListenAddr, cfg.GetCfg().SslCertFile, cfg.GetCfg().SslKeyFile, m)
		log.Printf("ListenAndServeTLS %v ", cfg.GetCfg().SslListenAddr)
		if err != nil {
			log.Fatal(err)
		}
	}()

	log.Printf("ListenAndServe %v ", cfg.GetCfg().HttpListenAddr)
	log.Fatal(http.ListenAndServe(cfg.GetCfg().HttpListenAddr, m))
}
Example #3
0
func init() {
	// All the parallelism are belong to us!
	runtime.GOMAXPROCS(runtime.NumCPU())

	// Print Version
	fmt.Println(VERSION)

	//Init Martini
	// render html templates from templates directory
	m.Use(render.Renderer(render.Options{
		Directory:  "templates",                 // Specify what path to load the templates from.
		Extensions: []string{".tmpl", ".html"},  // Specify extensions to load for templates.
		Charset:    "UTF-8",                     // Sets encoding for json and html content-types. Default is "UTF-8".
		Delims:     render.Delims{"{{%", "%}}"}, // Sets delimiters to the specified strings.
	}))

	//Init Conifg
	m.Use(cfg.Config())

	//InitDb()
	m.Use(db.MongoDB(cfg.GetCfg()))

	//InitSessionsAuth
	// Default our store to use Session cookies, so we don't leave logged in
	// users roaming around
	store := sessions.NewCookieStore([]byte(cfg.GetCfg().CookieSecret))
	store.Options(sessions.Options{
		MaxAge: 120,
	})
	m.Use(sessions.Sessions(cfg.GetCfg().SessionsName, store))
	m.Use(sessionauth.SessionUser(models.GenerateAnonymousUser))
	sessionauth.RedirectUrl = "/signin"
	sessionauth.RedirectParam = "next"

	//InitRouter
	InitRouter()
}