Пример #1
3
func setup() *gin.Engine {

	runtime.GOMAXPROCS(runtime.NumCPU())
	if _, err := database.InitDb(); err != nil {
		panic(err)
	}
	app := gin.New()

	app.Use(func(c *gin.Context) {
		c.Set(config.SecretKey, config.GetSecret())
		c.Next()
	})

	if config.GetEnv() == config.EnvProduction {
		app.Use(middleware.Recovery())
	} else {
		app.Use(gin.Recovery())
	}

	if config.GetEnv() == config.EnvTesting {
		gin.SetMode(gin.TestMode)
	} else {
		app.Use(gin.Logger())
	}

	app.Use(middleware.ErrorHandler())
	//Set up api v1
	routeV1(app)
	return app
}
Пример #2
0
func Server() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	if _, err := database.InitDb(); err != nil {
		panic(err)
	}

	app := gin.New()
	app.Use(func(c *gin.Context) {
		c.Set(config.SecretKey, config.GetSecret())
		c.Next()
	})
	if config.GetEnv() != config.EnvProduction {
		app.Use(gin.Logger())
		app.Use(gin.Recovery())
	} else {
		app.Use(middleware.Recovery())
	}

	app.Use(middleware.ErrorHandler())
	app.Static("/public", "./public")
	//Set up api v1
	setupApiV1(app)

	env := config.GetEnvValue()
	app.Run(env.Server.Host + ":" + strconv.Itoa(env.Server.Port))
}