Пример #1
1
func main() {
	e := echo.New()
	// the file server for rice. "app" is the folder where the files come from.
	assetHandler := http.FileServer(rice.MustFindBox("app").HTTPBox())
	// serves the index.html from rice
	e.GET("/", standard.WrapHandler(assetHandler))

	// servers other static files
	e.GET("/static/*", standard.WrapHandler(http.StripPrefix("/static/", assetHandler)))
	e.Run(standard.New(":3000"))
}
Пример #2
0
func main() {
	e := echo.New()

	// Middleware
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	// Login route
	e.POST("/login", login)

	// Unauthenticated route
	e.GET("/", accessible)

	// Restricted group
	r := e.Group("/restricted")

	// Configure middleware with the custom claims type
	config := middleware.JWTConfig{
		Claims:     &jwtCustomClaims{},
		SigningKey: []byte("secret"),
	}
	r.Use(middleware.JWTWithConfig(config))
	r.GET("", restricted)

	e.Run(standard.New(":1323"))
}
Пример #3
0
func NewServer(
	port uint16,
	registry Registry,
	transferCreator TransferCreator,
) *Server {
	addr := fmt.Sprintf(":%d", port)

	s := &Server{
		addr: addr,

		registry:        registry,
		transferCreator: transferCreator,
	}

	e := echo.New()
	e.Get("/ping", s.handleGetPing)
	e.Get("/version", s.handleGetVersion)
	e.Get("/transfers/:state", s.handleGetTransfers)
	e.Get("/transfer_results", s.handleGetTransferResults)
	e.Get("/transfer_results/:IP", s.handleGetTransferResultsByIP)
	e.Post("/transfers", s.handlePostTransfers)

	s.httpServer = standard.New(addr)
	s.httpServer.SetHandler(e)

	return s
}
Пример #4
0
func main() {

	c, err := importConfiguration("./config.json")
	if err != nil {
		fmt.Printf("Could not import the configuration file, check that it exists: %s\n", err.Error())
	}
	config = c

	e := echo.New()
	e.Pre(middleware.RemoveTrailingSlash())

	e.Post("/api/users", postUserHandler)
	e.Post("/api/users/:userID/clockin", clockInHandler)
	e.Post("/api/users/:userID/clockout", clockOutHandler)

	e.Get("/api/users/:userID", getUserHandler)
	e.Get("/api/users/:userID/lastpunch", getLastPunchHandler)
	e.Get("/api/users/:userID/punches", getPunchesHandler)

	e.Static("/pages", "Static")
	e.Static("/scripts", "Static/scripts")

	e.Run(standard.New(":8888"))

	//eventually we need to accept command line parameters.
}
Пример #5
0
func main() {
	if displayVersion {
		fmt.Printf("Abraracourcix v%s\n", version.Version)
		return
	}
	if debug {
		logging.SetLogging("DEBUG")
	} else {
		logging.SetLogging("INFO")
	}

	store, err := getStorage()
	if err != nil {
		log.Printf("[ERROR] [abraracourcix] %v", err)
		return
	}
	var auth *api.Authentication
	log.Printf("%s %s", username, password)
	if len(username) > 0 && len(password) > 0 {
		auth = &api.Authentication{
			Username: username,
			Password: password,
		}
	}
	ws := api.GetWebService(store, auth)
	if debug {
		ws.Debug()
	}
	log.Printf("[INFO] [abraracourcix] Launch Abraracourcix on %s using %s backend",
		port, backend)
	ws.Run(standard.New(fmt.Sprintf(":%s", port)))
}
Пример #6
0
func main() {
	// Parse command line arguments
	kingpin.Version("0.0.1")
	kingpin.Parse()

	// Prepare (optionally) embedded resources
	templateBox := rice.MustFindBox("template")
	staticHTTPBox := rice.MustFindBox("static").HTTPBox()
	staticServer := http.StripPrefix("/static/", http.FileServer(staticHTTPBox))

	e := echo.New()

	t := &Template{
		templates: template.Must(template.New("base").Parse(templateBox.MustString("base.html"))),
	}
	e.SetRenderer(t)

	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	e.GET("/static/*", standard.WrapHandler(staticServer))

	edit := e.Group("/edit")
	edit.Get("/*", EditHandler)
	edit.Post("/*", EditHandlerPost)

	go WaitForServer()
	e.Run(standard.New(fmt.Sprintf("127.0.0.1:%d", *args.Port)))
}
Пример #7
0
func main() {
	e := echo.New()

	// Debug mode
	e.SetDebug(true)

	//-------------------
	// Custom middleware
	//-------------------
	// Stats
	s := NewStats()
	e.Use(s.Process)
	e.GET("/stats", s.Handle) // Endpoint to get stats

	// Server header
	e.Use(ServerHeader)

	// Handler
	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Hello, World!")
	})

	// Start server
	e.Run(standard.New(":1323"))
}
Пример #8
0
func main() {
	serv := echo.New()
	serv.Use(middleware.Logger())
	serv.Use(middleware.Recover())
	// store := session.NewCookieStore([]byte("secret"))
	store, err := session.NewRedisStore(32, "tcp", "localhost:6379", "", []byte("secret"))
	if err != nil {
		panic(err)
	}
	serv.Use(session.Sessions("GSESSION", store))
	serv.Get("/", func(ctx echo.Context) error {
		session := session.Default(ctx)
		var count int
		v := session.Get("count")
		if v == nil {
			count = 0
		} else {
			count = v.(int)
			count += 1
		}
		session.Set("count", count)
		session.Save()
		ctx.JSON(200, map[string]interface{}{
			"visit": count,
		})
		return nil
	})
	serv.Run(standard.New(":8081"))
}
Пример #9
0
func main() {

	demoData := Data{
		Id:   5,
		Name: "User name",
		Tags: []string{"people", "customer", "developer"},
	}

	e := echo.New()
	e.SetDebug(true)
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())

	s := stats.New()
	e.Use(standard.WrapMiddleware(s.Handler))

	e.GET("/xml", func(c echo.Context) error {
		return c.XML(200, demoData)
	})

	e.GET("/json", func(c echo.Context) error {
		return c.JSON(200, demoData)
	})

	e.GET("/error", func(c echo.Context) error {
		return echo.NewHTTPError(500, "Error here")
	})

	e.Run(standard.New(":8888"))

}
Пример #10
0
func main() {
	log.SetFormatter(&log.JSONFormatter{})
	log.SetOutput(os.Stdout)
	log.SetLevel(log.InfoLevel)

	config := Config{
		Port: 8080,
	}

	e := echo.New()

	err := InitializeWebsocket(e)

	if err != nil {
		panic(err)
	}

	err = InitializeRenderers(e)

	if err != nil {
		panic(err)
	}

	e.GET("/", func(c echo.Context) error {
		return c.Render(http.StatusOK, "view/index.html", "")
	})

	log.Info(config)
	e.Run(standard.New(fmt.Sprintf(":%d", config.Port)))
}
Пример #11
0
func main() {
	if displayVersion {
		fmt.Printf("Tchoupi v%s\n", version.Version)
		return
	}
	if debug {
		logging.SetLogging("DEBUG")
	} else {
		logging.SetLogging("INFO")
	}

	var auth *api.Authentication
	log.Printf("%s %s", username, password)
	if len(username) > 0 && len(password) > 0 {
		auth = &api.Authentication{
			Username: username,
			Password: password,
		}
	}
	ws := api.GetWebService(auth)
	if debug {
		ws.Debug()
	}
	log.Printf("[INFO] Launch on %s", port)
	ws.Run(standard.New(fmt.Sprintf(":%s", port)))
}
Пример #12
0
func main() {
	e := echo.New()
	e.SetRenderer(common.Template)
	common.InitRoutes(e)
	common.InitPostgres()
	e.Run(standard.New(":8080"))
}
Пример #13
0
func main() {
	cfg := readConfig()
	jwtKey := []byte(cfg.JwtKey)

	mongoSession := createMongoSession()
	defer mongoSession.Close()

	db := mongoSession.DB(cfg.Database)
	userCollection := db.C(collections.UserCollectionName)

	e := echo.New()

	e.Get("/ping", func(c echo.Context) error {
		return c.String(http.StatusOK, "pong")
	})

	restService := rest.NewService(db)
	restGroup := e.Group("/collection")
	restGroup.Get("/:collection", restService.Get)
	restGroup.Post("/:collection", restService.Post)
	restGroup.Put("/:collection", restService.Put)
	restGroup.Delete("/:collection", restService.Delete)

	userService := user.NewService(userCollection, jwtKey)
	userGroup := e.Group("/user")
	userGroup.Post("/signup", userService.Signup)
	userGroup.Post("/confirm", userService.ConfirmSignup)
	userGroup.Post("/signin", userService.Signin)
	userGroup.Post("/forgot-password", userService.ForgotPassword)
	userGroup.Post("/reset-password", userService.ResetPassword)

	sessionService := session.NewService(userCollection, jwtKey)
	sessionMiddleware := middleware.CreateSessionMiddleware(userCollection, jwtKey)
	sessionGroup := e.Group("/session", sessionMiddleware)
	sessionGroup.Post("/signout", sessionService.Signout)
	sessionGroup.Post("/change-password", sessionService.ChangePassword)
	sessionGroup.Post("/change-email", sessionService.ChangeEmail)
	sessionGroup.Post("/set-profile", sessionService.SetProfile)

	adminService := admin.NewService(userCollection, jwtKey)
	adminSessionMiddleware := middleware.CreateAdminSessionMiddleware(userCollection, jwtKey)
	adminGroup := e.Group("/admin", adminSessionMiddleware)
	adminGroup.Get("/get-users", adminService.GetUsers)
	adminGroup.Post("/create-user", adminService.CreateUser)
	adminGroup.Post("/change-user-password", adminService.ChangeUserPassword)
	adminGroup.Post("/change-user-email", adminService.ChangeUserEmail)
	adminGroup.Post("/set-user-roles", adminService.SetUserRoles)
	adminGroup.Post("/set-user-profile", adminService.SetUserProfile)
	adminGroup.Delete("/remove-users", adminService.RemoveUsers)
	adminGroup.Post("/signout-users", adminService.SignoutUsers)
	adminGroup.Post("/suspend-users", adminService.SuspendUsers)
	adminGroup.Post("/unsuspend-users", adminService.UnsuspendUsers)
	adminGroup.Delete("/remove-unconfirmed-users", adminService.RemoveUnconfirmedUsers)
	adminGroup.Post("/remove-expired-reset-keys", adminService.RemoveExpiredResetKeys)

	fmt.Println("Listening at http://localhost:5025")
	std := standard.New(":5025")
	std.SetHandler(e)
	graceful.ListenAndServe(std.Server, 5*time.Second)
}
Пример #14
0
func main() {
	e := echo.New()
	e.SetDebug(true)

	// enable any filename to be loaded from in-memory file system
	e.GET("/*", standard.WrapHandler(myEmbeddedFiles.Handler))

	// read ufo.html from in-memory file system
	htmlb, err := myEmbeddedFiles.ReadFile("ufo.html")
	if err != nil {
		log.Fatal(err)
	}

	// convert to string
	html := string(htmlb)

	// serve ufo.html through "/"
	e.GET("/", func(c echo.Context) error {

		// serve it
		return c.HTML(http.StatusOK, html)
	})

	// try it -> http://localhost:1337/
	// http://localhost:1337/ufo.html
	// http://localhost:1337/public/README.md
	open.Run("http://localhost:1337/")
	e.Run(standard.New(":1337"))

}
Пример #15
0
func main() {
	// 支持根据参数打印版本信息
	global.PrintVersion(os.Stdout)

	savePid()

	logger.Init(ROOT+"/log", ConfigFile.MustValue("global", "log_level", "DEBUG"))

	go ServeBackGround()

	e := echo.New()

	serveStatic(e)

	e.Use(thirdmw.EchoLogger())
	e.Use(mw.Recover())
	e.Use(pwm.Installed(filterPrefixs))
	e.Use(pwm.HTTPError())
	e.Use(pwm.AutoLogin())

	frontG := e.Group("", thirdmw.EchoCache())
	controller.RegisterRoutes(frontG)

	frontG.GET("/admin", echo.HandlerFunc(admin.AdminIndex), pwm.NeedLogin(), pwm.AdminAuth())
	adminG := e.Group("/admin", pwm.NeedLogin(), pwm.AdminAuth())
	admin.RegisterRoutes(adminG)

	std := standard.New(getAddr())
	std.SetHandler(e)

	gracefulRun(std)
}
Пример #16
0
// Main function of application
func main() {
	config := NewConfig()
	app := &App{}
	router := app.NewRouter()

	log.Printf("Listening at port %s", config.ServerPort)
	router.Run(standard.New(config.ServerPort))
}
Пример #17
0
func main() {
	e := echo.New()
	api := e.Group("/api/v1")
	{
		api.Get("/posts/:keyword", kirara.GetPosts)
	}
	e.Run(standard.New("127.0.0.1:8888"))
}
Пример #18
0
func main() {
	// the appengine package provides a convenient method to handle the health-check requests
	// and also run the app on the correct port. We just need to add Echo to the default handler
	s := standard.New(":8080")
	s.SetHandler(e)
	http.Handle("/", s)
	appengine.Main()
}
Пример #19
0
func (s *ApiServer) Run() error {
	s.RegisterMiddleware()
	s.RegisterURL()
	std := standard.New(s.webAddr)
	std.SetHandler(s)
	graceful.ListenAndServe(std.Server, 5*time.Second)
	return nil
}
Пример #20
0
func main() {
	go func() {
		http.ListenAndServe(":6060", nil)
	}()

	router := app.BuildInstance()
	router.Run(standard.New(":3000"))
}
Пример #21
0
func main() {
	e := echo.New()
	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Six sick bricks tick")
	})
	std := standard.New(":1323")
	std.SetHandler(e)
	gracehttp.Serve(std.Server)
}
Пример #22
0
func main() {
	if err := godotenv.Load(); err != nil {
		panic(err)
	}

	api := echo.New(){hek:go-api:staticEndpoint}
	api.Get("{hek:go-api:rootEndpoint}", Hi)
	api.Run(standard.New(os.Getenv("ADDR")))
}
Пример #23
0
func main() {
	// Setup
	e := echo.New()
	e.GET("/", func(c echo.Context) error {
		return c.String(http.StatusOK, "Sue sews rose on slow joe crows nose")
	})
	std := standard.New(":1323")
	std.SetHandler(e)
	graceful.ListenAndServe(std.Server, 5*time.Second)
}
Пример #24
0
func createMux() *echo.Echo {
	e := echo.New()

	// note: we don't need to provide the middleware or static handlers, that's taken care of by the platform
	// app engine has it's own "main" wrapper - we just need to hook echo into the default handler
	s := standard.New("")
	s.SetHandler(e)
	http.Handle("/", s)

	return e
}
Пример #25
0
// StartHTTP listens on the configured ports for the REST application
func (s *Service) StartHTTP() error {
	address := fmt.Sprintf("%s:%d", s.config.Interface, s.config.Port)

	URL = address
	// Use middlewares
	s.Router.Use(mw.Gzip())
	s.Router.Use(mw.Logger())
	s.Router.Run(standard.New(address))

	return nil
}
Пример #26
0
func (app *App) Run() {
	app.Echo.SetRenderer(app.Templates)

	app.Echo.Use(middleware.Logger())
	app.Echo.Use(middleware.Recover())

	app.Echo.Get("/", home())
	app.Echo.Get("/*", client())

	app.Echo.Run(standard.New(":" + app.Config.Get("port")))
}
Пример #27
0
func main() {
	runtime.GOMAXPROCS(runtime.NumCPU())
	serv := echo.New()
	serv.Use(middleware.Logger())
	serv.Use(middleware.Recover())
	r := pongor.GetRenderer()
	serv.SetRenderer(r)
	serv.Get("/pongo", PongoGetHandler())
	serv.Get("/string", StringHandler())

	serv.Run(standard.New(":8002"))
	// serv.Run(fasthttp.New(":8002"))
}
Пример #28
-1
func main() {
	e := echo.New()
	e.Use(middleware.Logger())
	e.Use(middleware.Recover())
	e.Use(middleware.Static("../public"))
	e.GET("/ws", standard.WrapHandler(http.HandlerFunc(hello())))
	e.Run(standard.New(":1323"))
}
Пример #29
-1
func main() {
	e := echo.New()

	e.Use(middleware.Logger())
	e.Use(middleware.Recover())
	e.Use(middleware.Static("public"))

	e.POST("/upload", upload)

	e.Run(standard.New(":1323"))
}
Пример #30
-1
func main() {
	e := echo.New()

	e.Use(middleware.Logger())
	e.Use(middleware.Recover())
	e.Use(middleware.Static("public"))

	handler := Handler{"Hoł hoł"}
	e.GET("/ws", standard.WrapHandler(websocket.Handler(handler.WS)))

	e.Run(standard.New(":1323"))
}