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

	e := echo.New()
	e.Use(mw.Logger())
	e.Use(mw.Recover())
	e.Use(mw.StripTrailingSlash())
	e.Use(mw.Gzip())
	e.Use(cors.Default().Handler)

	bundle, _ := ioutil.ReadFile("./build/bundle.js")

	// stats
	s := stats.New()
	e.Use(s.Handler)
	e.Get("/stats", func(c *echo.Context) error {
		return c.JSON(http.StatusOK, s.Data())
	})
	// static files
	e.Static("/public/css", "public/css")
	e.Static("/universal.js", "./build/bundle.js")
	e.Favicon("public/favicon.ico")

	e.Get("/", selfjs.New(runtime.NumCPU(), string(bundle), rss))
	e.Get("/about", selfjs.New(runtime.NumCPU(), string(bundle), loremJSON()))

	e.Get("/api/data", apiFrontPage)
	e.Get("/api/anotherpage", apiAnotherPage)
	go tick()
	fmt.Println("serving at port 3000")
	e.Run(":3000")
}
Пример #2
0
func main() {
	InitDB()
	RunMigrations()

	e := echo.New()

	e.Use(mw.Logger())
	e.Use(mw.Recover())
	e.Use(mw.StripTrailingSlash())

	//e.Get("/", index)

	m := e.Group("/monsters")
	m.Use(JWTAuth(SigningKey))

	m.Get("", IndexMonster)
	m.Post("", CreateMonster)
	m.Get("/:id", ReadMonster)
	m.Put("/:id", UpdateMonster)
	m.Delete("/:id", DeleteMonster)

	l := e.Group("/languages")
	l.Use(JWTAuth(SigningKey))
	l.Get("", LanguageIndex)
	l.Post("", CreateLanguage)
	l.Get("/:id", LanguageDetail)
	l.Delete("/:id", DeleteLanguage)

	u := e.Group("/users")
	u.Post("", CreateUser)
	u.Post("/login", LoginUser)
	u.Get("/:id", UserDetail)
	u.Delete("/:id", DeleteUser)

	c := e.Group("/campaigns")
	c.Post("", CreateCampaign)
	c.Get("", IndexCampaign)
	c.Get("/:id", ReadCampaign)
	c.Put("/:id", UpdateCampaign)
	c.Delete("/:id", DeleteCampaign)

	/*
		en := e.Group("/encounters")
		en.Post("", CreateEncounter)
		en.Get("", IndexEncounter)
		en.Get("/:id", ReadEncounter)
		en.Put("/:id", UpdateEncounter)
		en.Delete("/:id", DeleteEncounter)
	*/

	log.Printf("Serving on port: 4242")
	e.Run(":4242")
}
Пример #3
0
func main() {
	// Echo instance
	e := echo.New()

	// Debug mode
	e.SetDebug(true)

	//------------
	// Middleware
	//------------

	// Logger
	e.Use(mw.Logger())

	// Recover
	e.Use(mw.Recover())

	// Basic auth
	e.Use(mw.BasicAuth(func(usr, pwd string) bool {
		if usr == "joe" && pwd == "secret" {
			return true
		}
		return false
	}))

	//-------
	// Slash
	//-------

	e.Use(mw.StripTrailingSlash())

	// or

	//	e.Use(mw.RedirectToSlash())

	// Gzip
	e.Use(mw.Gzip())

	// Routes
	e.Get("/", hello)

	// Start server
	e.Run(":1323")
}