Пример #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
}
func StartGin() {
	gin.SetMode(gin.ReleaseMode)

	router := gin.New()
	gin.Logger()
	router.Use(rateLimit, gin.Recovery())
	router.Use(gin.Logger())
	router.LoadHTMLGlob("resources/*.templ.html")
	router.Static("/static", "resources/static")
	router.GET("/", MyBenchLogger(), index)
	router.GET("/auth", authentication.RequireTokenAuthentication(), index)
	router.POST("/test", controllers.Login)
	router.GET("/room/:name", roomGET)
	router.POST("/room-post/:roomid", roomPOST)
	router.GET("/stream/:roomid", streamRoom)

	//mongodb user create
	uc := user_controllers.NewUserController(getSession())
	router.GET("/user", uc.GetUser)
	router.GET("/message", uc.GetMessage)
	router.POST("/message", uc.CreateMessage)
	router.POST("/user", uc.CreateUser)
	router.DELETE("/user/:id", uc.RemoveUser)

	router.Run(":5001")

}
Пример #3
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())

	role := config.mustGetString("postgres", "role")
	database := config.mustGetString("postgres", "database")
	ip := config.mustGetString("postgres", "ip")
	password := config.mustGetString("postgres", "password")
	services.InitDBConnection(role, password, database, ip)

	api_key := config.mustGetString("parsemap", "api_key")
	r := gin.New()
	r.Use(gzip.Gzip(gzip.DefaultCompression))
	r.Use(gin.Logger())
	r.Use(gin.Recovery())
	r.Use(gin.ErrorLogger())

	v2 := r.Group("/v2")
	services.GetHandlersV2(v2, api_key)

	var wg sync.WaitGroup
	wg.Add(2)
	go startServer(r, &wg)
	go startTLSServer(r, &wg)
	wg.Wait()
}
Пример #4
0
func Run() {
	r := gin.New()

	// Global middlewares
	// If use gin.Logger middlewares, it send duplicated request.
	switch config.Environment {
	case "DEVELOPMENT":
		r.Use(gin.Logger())
	case "TEST":
		r.Use(log.AccessLogger())
	case "PRODUCTION":
		r.Use(log.AccessLogger())
	}
	r.Use(gin.Recovery())
	r.Use(CORSMiddleware())
	switch config.Frontend {
	case "CanJS":
		canjs.LoadPage(r)
	default:
		canjs.LoadPage(r)
	}
	api.RouteAPI(r)

	// Listen and server on 0.0.0.0:3001
	//    r.Run("localhost:3001")
	r.Run(":3001")
}
Пример #5
0
func main() {

	var errd error

	port := os.Getenv("PORT")

	if port == "" {
		log.Fatal("$PORT seadmata")
	}

	db, errd = sql.Open("postgres", os.Getenv("DATABASE_URL"))
	if errd != nil {
		log.Fatalf("Viga andmebaasiga connectimisel: %q", errd)
	}

	router := gin.New()
	router.Use(gin.Logger())
	router.LoadHTMLGlob("templates/*.tmpl.html")
	router.Static("/static", "static")

	router.GET("/", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.tmpl.html", nil)
	})

	router.GET("/db", dbFunc)

	router.Run(":" + port)
}
Пример #6
0
func main() {

	err := modem.Connect()
	if err != nil {
		log.Printf("ConnectModem: error connecting to %s, %s\r\n", modem.DeviceId, err)
		log.Printf("commport: %s\r\n", config.CommPort)
		log.Printf("baud: %d\r\n", config.Baud)
		os.Exit(1)
	}
	err = modem.InitialiseModem()
	if err != nil {
		log.Printf("InitModem: error initialising %s, %s\r\n", modem.DeviceId, err)
	}

	// Creates a router without any middleware by default
	//gin.SetMode(gin.ReleaseMode)
	r := gin.New()

	// Global middlewares
	r.Use(gin.Logger())
	r.Use(gin.Recovery())
	r.Use(SetJellyBeans())

	api := r.Group("/api")
	{
		api.GET("/sms", index)
		api.POST("/sms", sendSMS)
	}

	go worker()
	// Listen and server on 0.0.0.0:8951
	r.Run(bindaddress)

}
Пример #7
0
func createRouter() {
	r = gin.New()
	r.Use(gin.Logger())
	r.Use(gin.Recovery())
	r.Use(corsMiddleware)
	r.Use(i18nMiddleware)
}
Пример #8
0
func main() {

	// Set Working direcotry
	_, filename, _, _ := runtime.Caller(0)
	var dir, _ = filepath.Split(filename)
	os.Chdir(dir)

	// Echo instance
	r := gin.New()

	// Global middleware
	r.Use(gin.Logger())
	r.Use(gin.Recovery())

	// Database
	r.Use(config.DbMw())

	// Sessions
	r.Use(config.SessionMw())

	// Templates
	//	config.SetRenderer(e)

	// Routes
	config.Routes(r)

	// Start server
	var port = ":3333"
	log.Println("HTTP Server running on port :3333!")
	r.Run(port)
}
Пример #9
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))
}
Пример #10
0
// NewOpenVPNAuthd creates a new service for shipping out the openvpn config
func NewOpenVPNAuthd(cfg *AuthConfig) (OpenVPNAuthd, error) {
	//var err error

	glog.Infof("creating a new openvpn authd service, config: %s", cfg)

	service := new(openvpnAuthd)
	service.config = cfg

	// step: create the vault client
	glog.V(3).Infof("creating the vault client, address: %s, username: %s", cfg.VaultURL, cfg.VaultUsername)
	client, err := NewVaultClient(cfg.VaultURL, cfg.VaultCaFile, cfg.VaultTLSVerify)
	if err != nil {
		return nil, fmt.Errorf("failed to create a vault client, error: %s", err)
	}
	service.vault = client

	// step: attempt to authenticate to vault
	err = client.Authenticate(cfg.VaultUsername, cfg.VaultPassword)
	if err != nil {
		return nil, fmt.Errorf("failed to authenticate to vault, error: %s", err)
	}

	// step: create the gin router
	router := gin.New()
	router.LoadHTMLGlob("templates/*")
	router.Use(gin.Logger())
	router.Use(gin.Recovery())
	router.GET("/health", service.healthHandler)
	router.GET("/", service.openVPNHandler)

	service.router = router

	return service, nil
}
Пример #11
0
func main() {
	port := os.Getenv("PORT")

	if port == "" {
		log.Fatal("$PORT must be set")
	}

	router := gin.New()
	router.Use(gin.Logger())
	router.Static("/js", "js")
	router.Static("/static", "static")

	router.LoadHTMLGlob("templates/*.html")

	router.GET("/", func(c *gin.Context) {
		c.HTML(http.StatusOK, "index.html", nil)
	})

	router.GET("/pages/:page", func(c *gin.Context) {
		page := fmt.Sprint(c.Params.ByName("page"), ".html")
		c.HTML(http.StatusOK, page, nil)
	})

	router.GET("/ssbapi/:number", ssbHandler)

	router.Run(":" + port)
}
Пример #12
0
func main() {
	flag.Parse()
	conf, err := loadConfiguration()
	if err != nil {
		log.Fatal(err)
		return
	}
	verbose, err := strconv.ParseBool(conf.Verbose)
	if err != nil {
		log.Fatal(err)
		return
	}
	airbrakeProjectID, err := strconv.ParseInt(conf.AirbrakeProjectID, 10, 64)
	if err != nil {
		log.Fatal(err)
		return
	}
	airbrake = gobrake.NewNotifier(airbrakeProjectID, conf.AirbrakeProjectKey)
	r := gin.New()
	r.Use(airbrakeRecovery(airbrake)) // Use airbrakeRecovery as early as possible
	r.Use(newrelic.NewRelic(conf.NewRelicLicenseKey, conf.DbName, verbose))
	r.Use(gin.Logger())
	buildRoutes(r)
	r.Run(conf.BindAddress) // listen and serve
}
Пример #13
0
func main() {

	//	nuCPU := runtime.NumCPU()
	//	runtime.GOMAXPROCS(nuCPU)
	//	fmt.Printf("Running with %d CPUs\n", nuCPU)

	if !configs.Debug {
		gin.SetMode(gin.ReleaseMode)
	}
	if configs.Debug {
		r.Use(gin.Logger())
	}
	r.Use(gin.Recovery())
	r.Static("/static", "./static")
	//	r.LoadHTMLGlob("templates/**/*.html")
	//	r.GET("/", indexPageHandler)
	r.GET("/", loginRequired(indexPageHandler))
	r.GET(login_page, loginHandler)
	r.POST(login_page, authLoginHandler)
	r.POST("/logout", logoutHandler)
	r.GET("/upload", loginRequired(upload))
	r.POST("/upload", loginRequired(upload))
	r.GET("/page/:link", pageRouter)
	r.NoRoute(func(c *gin.Context) {
		c.JSON(http.StatusNotFound, gin.H{"code": "PAGE_NOT_FOUND", "message": "Page not found"})
	})

	//	r.Run(":8080") // listen and serve on 0.0.0.0:8080

	http.ListenAndServe(":8080", CSRF(r))
	//	http.ListenAndServeTLS(":8080", "/etc/nginx/ssl/nginx.crt", "/etc/nginx/ssl/nginx.key", CSRF(r))
}
Пример #14
0
func main() {

	// fire this up
	router := gin.Default()
	router.Use(gin.Logger())

	// load the dang templates
	router.LoadHTMLGlob("templates/*.html")
	// router.Use(static.Serve("/static", static.LocalFile("html", false)))
	router.Static("/static", "static")

	// handle root
	router.GET("/", func(c *gin.Context) {
		c.String(http.StatusOK, "wat")
	})

	// check the incoming phrase
	router.GET("/blink/:phrase", func(c *gin.Context) {
		phrase := c.Param("phrase")
		c.HTML(http.StatusOK, "main.html", gin.H{
			"title":               phrase,
			"phrase":              phrase,
			"twitter_handle":      "mike_dory",
			"google_analytics_id": "XXXXX-XX",
		})
	})

	// run!
	router.Run(":8081")

}
Пример #15
0
func main() {
	r = gin.Default()

	// Global middleware
	r.Use(gin.Logger())
	r.Use(gin.Recovery())
	r.Static("/assets", "./assets")
	r.LoadHTMLGlob("view/*")

	// Simple group: v1
	v1 := r.Group("/")
	{
		v1.GET("/", home.Dispatch)
	}

	// Simple group: v2
	v2 := r.Group("/api")
	{
		v2.GET("/login", api.Login)
		v2.GET("/mail/list", api.MailList)
		v2.GET("/mail/detail", api.MailDetail)
		v2.GET("/mail/box", api.MailBox)
		v2.GET("/mail/send", api.MailSend)
		v2.GET("/mail/set", api.MailSet)
	}

	r.Run(":8081")
}
Пример #16
0
func main() {

	ROOT_DIR, _ = osext.ExecutableFolder()
	config.LoadConfig(ge.BuildFullPath(ROOT_DIR, "config.json"))

	GE = ge.NewGalaxyEmpires(ge.BuildFullPath(ROOT_DIR, "data"), ge.CoordinatesStruct{1, 15, 5})

	r := gin.New()
	r.Use(gin.Logger())
	r.Use(gin.Recovery())
	r.Use(middleware.Errors("", "", nil))

	debug.AssignDebugHandlers(r.Group("/debug"))

	handlers.NewAccountHandler(r.Group("/account"), GE)
	handlers.NewPlayerHandler(r.Group("/player", middleware.Authentication([]byte(config.Config.Key))), GE)
	handlers.NewPlanetHandler(r.Group("/planet", middleware.Authentication([]byte(config.Config.Key))), GE)

	r.Static("/assets", ROOT_DIR+"/web/assets")
	r.StaticFile("/", ROOT_DIR+"/web/index.html")

	if err := r.Run(":" + config.Config.Port); err != nil {
		panic(err)
	}

}
Пример #17
0
func main() {
	router := gin.New()
	router.LoadHTMLGlob("templates/*")
	router.Use(gin.Logger())
	router.Use(gin.Recovery())

	v1 := router.Group("/v1")
	// Example for binding JSON ({"user": "******", "password": "******"})
	v1.POST("/loginJSON", func(c *gin.Context) {
		var json Login
		if c.BindJSON(&json) == nil {
			if json.User == "manu" && json.Password == "123" {
				c.JSON(http.StatusOK, gin.H{"status": "you are logged in"})
			} else {
				c.JSON(http.StatusUnauthorized, gin.H{"status": "unauthorized"})
			}
		}
	})

	router.GET("/login", func(c *gin.Context) {
		c.HTML(http.StatusOK, "loginform.tmpl", gin.H{
			"Title": "Login Page",
		})
	})

	// Example for binding a HTML form (user=manu&password=123)
	v1.POST("/loginForm", Hello(), Lolo)

	// Listen and server on 0.0.0.0:8080
	router.Run(":8080")
}
Пример #18
0
func main() {

	//	当前目录
	rootDir := filepath.Dir(os.Args[0])

	//	设置配置文件
	err := config.SetRootDir(rootDir)
	if err != nil {
		log.Fatal(err)
		return
	}

	//	启动定时任务
	job.Start()

	//	http监听端口
	port := config.Int("http", "port", 9000)
	serverAddress := fmt.Sprintf(":%d", port)

	r := gin.New()
	r.Use(gin.Logger())

	//	注册路由
	RegisterRoute(r)

	r.Run(serverAddress) // listen and serve on 0.0.0.0:8080
}
Пример #19
0
Файл: main.go Проект: t2y/misc
func main() {
	Logger.Formatter = new(logrus.JSONFormatter)

	// init
	db := InitDatabase("./myapp.db")
	defer db.Close()

	r := gin.Default()

	// middleware
	r.Use(func(c *gin.Context) {
		c.Set("DB", db)
		c.Next()
	})
	r.Use(gin.Logger())
	r.Use(gin.Recovery())
	r.Use(SetProperties)

	// handlers
	r.GET("/users/", ListUsers)
	r.GET("/users/:name", GetUser)
	r.POST("/users/:name", RegisterUser)
	r.PUT("/users/:name", UpdateUserInfo)
	r.DELETE("/users/:name", DeleteUserInfo)

	r.Run(":8000")
}
Пример #20
0
func main() {
	e := gin.New()
	e.Use(gin.Logger())
	e.Use(gin.Recovery())
	e.GET("/gui/*filepath", static)
	e.GET("/api/stats", stats)
	e.Run(":1488")
}
Пример #21
0
func init() {
	router := gin.New()

	router.Use(gin.Logger())
	router.Use(gin.Recovery())
	router.Use()

}
Пример #22
0
func main() {
	router := gin.New()
	// Global middleware
	router.Use(gin.Logger())
	router.Use(gin.Recovery())
	router.GET("/animated.gif", animatedgif)
	router.Run("0.0.0.0:8000")
}
Пример #23
0
func (s *Server) SeDefaultMiddleware() error {
	s.Router.Use(gin.Logger())
	s.Router.Use(gin.Recovery())
	s.Router.Use(middleware.Cors())
	s.Router.Use(middleware.Application(s.Config))

	return nil
}
Пример #24
0
func main() {
	if !cfg.Debug {
		gin.SetMode(gin.ReleaseMode)
	}

	r := gin.New()

	// Global middleware
	r.Use(gin.Logger())
	r.Use(gin.Recovery())

	r.HTMLRender = pongo2gin.Default()

	r.Static("/static", "./static")

	r.GET("/", func(c *gin.Context) {
		c.HTML(200, "index.html", pongo2.Context{"name": "world"})
	})

	wsServer := NewWsServer()

	r.GET("/ws/", func(c *gin.Context) {
		channel := wsServer.GetChannel(BROADCAST_CHANNEL)
		channel.ServeHTTP(c.Writer, c.Request)
	})

	r.GET("/ws/:channel", func(c *gin.Context) {
		name := c.Param("channel")
		channel := wsServer.GetChannel(name)
		channel.ServeHTTP(c.Writer, c.Request)
	})

	if !cfg.Debug {
		srv := &graceful.Server{
			Timeout: 10 * time.Second,

			Server: &http.Server{
				Addr:           cfg.Listen,
				Handler:        r,
				ReadTimeout:    10 * time.Second,
				WriteTimeout:   10 * time.Second,
				MaxHeaderBytes: 1 << 20,
			},
		}

		srv.ListenAndServe()
	} else {
		srv := http.Server{
			Addr:           cfg.Listen,
			Handler:        r,
			ReadTimeout:    10 * time.Second,
			WriteTimeout:   10 * time.Second,
			MaxHeaderBytes: 1 << 20,
		}
		srv.ListenAndServe()
	}
}
Пример #25
0
func engine() *gin.Engine {
	router := gin.New()
	router.Use(gin.Logger())
	router.Use(gin.Recovery())
	router.GET("/", rootGET)
	router.POST("/slack", slackPOST)

	return router
}
Пример #26
0
func init() {
	r = gin.New()

	r.Use(gin.Logger())
	r.Use(gin.Recovery())

	db := DBProvider.InitDBConnection()
	user.UserRouter(r.Group("/user"), db)
}
Пример #27
0
func StartServer() error {
	router := gin.New()
	router.Use(gin.Logger())
	router.Use(gin.Recovery())

	prepareRoutes(router)
	router.Run(":8080")
	return nil
}
Пример #28
0
func main() {
	logger.Log.Info("Loading Quarid...")
	c := config.Get()

	r := http.Router(
		gin.Logger(),
		gin.Recovery(),
	)
	r.Run(c.GetString("listen"))
}
Пример #29
0
// Build will do action of building an app
func (g *Gallang) Build() {
	g.App = gin.New()
	g.App.Use(gin.Logger())
	g.App.Use(gin.Recovery())

	routes := getRouteDefinition()

	for _, item := range routes {
		g.RouteHandle(item.method, item.endpoint, item.worker)
	}
}
Пример #30
0
// Router creates a new router with handlers
func Router() *gin.Engine {
	router := gin.New()

	router.Use(gin.Logger())
	router.Use(gin.Recovery())

	router.GET("/", helloWorldHandler)
	router.GET("/greet", greetingHandler)

	return router
}