Exemplo n.º 1
0
func main() {
	tracelog.Start(tracelog.LevelInfo)

	RunServer()

	tracelog.Stop()
}
Exemplo n.º 2
0
func main() {
	tracelog.Start(tracelog.LevelTrace)

	// Init mongo
	tracelog.Started("main", "Initializing Mongo")
	err := mongo.Startup(helper.MainGoRoutine)
	if err != nil {
		tracelog.CompletedError(err, helper.MainGoRoutine, "initApp")
		os.Exit(1)
	}

	// Load message strings
	localize.Init("en-US")

	SessionConfig, err := session.GetSessionConfig("session")

	tracelog.Trace("main", "SessionConfig", "Session : On[%v]", SessionConfig.On)
	tracelog.Trace("main", "SessionConfig", "Session : On[%v]", SessionConfig.Provider)
	tracelog.Trace("main", "SessionConfig", "Session : On[%v]", SessionConfig.SavePath)

	beego.SessionOn = SessionConfig.On
	beego.SessionProvider = SessionConfig.Provider
	beego.SessionSavePath = SessionConfig.SavePath

	beego.Run()

	tracelog.Completed(helper.MainGoRoutine, "Website Shutdown")
	tracelog.Stop()
}
Exemplo n.º 3
0
func main() {

	tracelog.Start(tracelog.LevelTrace)
	err := mongo.Startup(helper.MainGoRoutine)
	if err != nil {
		tracelog.CompletedError(err, helper.MainGoRoutine, "initApp")
		os.Exit(1)
	} else {
		fmt.Println("mongodb启动正常")
	}
	beego.Run()

	tracelog.Completed(helper.MainGoRoutine, "Website Shutdown")
	tracelog.Stop()
}
Exemplo n.º 4
0
func main() {
	tracelog.Start(tracelog.LEVEL_TRACE)

	// Init mongo
	tracelog.STARTED("main", "Initializing Mongo")
	err := mongo.Startup(helper.MAIN_GO_ROUTINE)
	if err != nil {
		tracelog.COMPLETED_ERROR(err, helper.MAIN_GO_ROUTINE, "initApp")
		os.Exit(1)
	}

	beego.Run()

	tracelog.STARTED(helper.MAIN_GO_ROUTINE, "Website Shutdown")
	tracelog.Stop()
}
Exemplo n.º 5
0
func main() {
	tracelog.Start(tracelog.LEVEL_TRACE)

	// Init mongo
	tracelog.Started("main", "Initializing Mongo")
	err := mongo.Startup(helper.MAIN_GO_ROUTINE)
	if err != nil {
		tracelog.CompletedError(err, helper.MAIN_GO_ROUTINE, "initApp")
		os.Exit(1)
	}

	// Load message strings
	localize.Init("en-US")

	beego.Run()

	tracelog.Completed(helper.MAIN_GO_ROUTINE, "Website Shutdown")
	tracelog.Stop()
}
func main() {
	tracelog.Start(tracelog.LevelTrace)
	//tracelog.Start(tracelog.LevelInfo)

	var port = os.Getenv("PORT")

	if port == "" {
		tracelog.Error(nil, "The PORT environment variable has not been set.", "main")
		os.Exit(1)
	}

	var myGasFeedBaseUrl = os.Getenv("MY_GAS_FEED_BASE_URL")
	if myGasFeedBaseUrl == "" {
		tracelog.Error(nil, "The MY_GAS_FEED_BASE_URL environment variable has not been set.", "main")
	}
	SetMyGasFeedBaseUrl(myGasFeedBaseUrl)

	var myGasFeedApiKey = os.Getenv("MY_GAS_FEED_API_KEY")
	if myGasFeedApiKey == "" {
		tracelog.Error(nil, "The MY_GAS_FEED_API_KEY environment variable has not been set.", "main")
	}
	SetMyGasFeedApiKey(myGasFeedApiKey)

	tracelog.Info("Started", "main", "Gas Price Service is starting and listening on port %s", port)

	router := mux.NewRouter()
	for _, route := range routes {
		var handler http.Handler

		handler = route.HandlerFunc
		handler = Logger(handler, route.Name)

		router.Methods(route.Method).Path(route.Pattern).Name(route.Name).Handler(handler)
	}

	err := http.ListenAndServe(":"+port, router)
	if err != nil {
		tracelog.Error(err, "An error occurred while attempting to listen and serve", "main")
	}

	tracelog.Info("Stopped", "main", "Gas Price Service has been terminated")
	tracelog.Stop()
}
Exemplo n.º 7
0
func main() {
	tracelog.Start(tracelog.LevelTrace)

	// Init mongo
	tracelog.Started("main", "Initializing Mongo")
	err := mongo.Startup(helper.MainGoRoutine)
	if err != nil {
		tracelog.CompletedError(err, helper.MainGoRoutine, "initApp")
		os.Exit(1)
	}

	// Load message strings
	localize.Init("en-US")

	beego.Run()

	tracelog.Completed(helper.MainGoRoutine, "Website Shutdown")
	tracelog.Stop()
}
Exemplo n.º 8
0
func main() {
	tracelog.Start(tracelog.LevelTrace)

	// Init mongo
	tracelog.Started("main", "Initializing Mongo")
	err := mongo.Startup(helper.MainGoRoutine)
	if err != nil {
		tracelog.CompletedError(err, helper.MainGoRoutine, "initApp")
		os.Exit(1)
	}

	// Load message strings
	localize.Init("en-US")
	beego.BConfig.WebConfig.Session.SessionOn = true
	globalSessions, _ = session.NewManager("redis", `{"cookieName":"gosessionid","gclifetime":3600,"ProviderConfig":"127.0.0.1:6379"}`)
	go globalSessions.GC()
	beego.Run()

	tracelog.Completed(helper.MainGoRoutine, "Website Shutdown")
	tracelog.Stop()
}
func main() {
	// tracelog.Start(tracelog.LevelTrace)
	tracelog.Start(tracelog.LevelInfo)

	var port = os.Getenv("PORT")
	if port == "" {
		tracelog.Error(nil, "The PORT environment variable has not been set.", "main")
		os.Exit(1)
	}

	var mapsApiKey = os.Getenv("GOOGLE_MAPS_API_KEY")
	if mapsApiKey == "" {
		tracelog.Error(nil, "The GOOGLE_MAPS_API_KEY enviornment variable has not been set.", "main")
		os.Exit(2)
	}
	SetGoogleAPIKey(mapsApiKey)

	tracelog.Info("Started", "main", "Google Reverse Geocode Service is starting and listening on port %s", port)

	router := mux.NewRouter()
	for _, route := range routes {
		var handler http.Handler

		handler = route.HandlerFunc
		handler = Logger(handler, route.Name)

		router.Methods(route.Method).Path(route.Pattern).Name(route.Name).Handler(handler)
	}

	err := http.ListenAndServe(":"+port, router)
	if err != nil {
		tracelog.Error(err, "An error occurred while attempting to listen and serve.", "main")
		os.Exit(3)
	}

	tracelog.Info("Stopped", "main", "Google Reverse Geocode Service has been terminated")
	tracelog.Stop()
}
Exemplo n.º 10
0
// Main go routine
func main() {
	// Start logger
	tracelog.StartFile(1, utils.ConfigEntry("LogDir"), 1)

	// Get new cookie store
	store := sessions.NewCookieStore([]byte(utils.ConfigEntry("SecretKey")))
	store.Options = &sessions.Options{
		Path:     "/",
		MaxAge:   3600,
		HttpOnly: true,
	}

	// Create DB connection
	dbHandle := utils.DbHandle()
	// Close DB
	defer dbHandle.Close()

	// Init Models
	sm := &models.Song{DbHandle: dbHandle}
	nm := &models.Nonce{DbHandle: dbHandle}
	um := models.NewUser(dbHandle)

	// Init Controllers
	sc := &controllers.Song{SM: sm}
	nc := &controllers.Nonce{NM: nm}
	vc := &controllers.View{Store: store}
	uc := &controllers.User{UM: um, Store: store}

	// Init Gin
	mux := gin.Default()

	// Load templates
	mux.LoadHTMLGlob("app/views/*")

	// Serve static files
	mux.Static("/public", utils.ConfigEntry("StaticDir"))

	// Routes for static pages
	static := mux.Group("/")
	{
		static.GET("/", vc.Index)
		static.GET("/about", vc.About)
		static.GET("/tos", vc.Tos)
		static.GET("/privacy-policy", vc.PrivacyPolicy)
		static.GET("/credits", vc.Credits)
	}

	// Routes that don't need authorization
	basic := mux.Group("/api/v1")
	basic.Use(middlewares.Session(store))
	{
		basic.GET("/nonce", nc.Create)
		basic.GET("/users/check-username/:username", uc.CheckUsername)
		basic.GET("/users/check-email/:email", uc.CheckEmail)
		basic.POST("/users/login", uc.Login)
		basic.POST("/users/register", uc.Register)
	}

	// Routes that need authorization
	auth := mux.Group("/api/v1")
	auth.Use(middlewares.Session(store), middlewares.UserAuth(store), middlewares.Nonce(nm))
	{
		auth.GET("/songs", sc.Index)
		auth.GET("/users/delete/:nonce", uc.ConfirmDelete)
		auth.POST("/users/delete", uc.Delete)
		auth.POST("/users/update", uc.Update)
		auth.POST("/users/logout", uc.Logout)
	}

	// Listen and serve on 0.0.0.0:8080
	mux.Run(":9000")

	tracelog.Stop()
}