コード例 #1
0
ファイル: server.go プロジェクト: dyweb/Ayi
func NewAyiServer(port int) *Server {
	server := Server{}
	server.Port = port
	server.Router = web.New(ayiContext{})

	server.Router.Middleware(web.LoggerMiddleware)
	box := rice.MustFindBox("app-web-public")
	// NOTE: index file does not work, because isDir return false
	server.Router.Middleware(web.StaticMiddlewareFromDir(box.HTTPBox(), web.StaticOption{}))
	server.Router.Get("/", (*ayiContext).Index)
	return &server
}
コード例 #2
0
ファイル: router.go プロジェクト: ntfrnzn/bakingdish
func SetupTest() *web.Router {
	// regarding the static middleware, documentation for the
	// below is not terribly clear -- in order to get the
	// automatic loading of "/path/index.html" when requesting
	// just "/path/", it _must_ be specified as a web.StaticOption

	// Create your router
	router := web.New(Context{}).
		Middleware(web.LoggerMiddleware).         // Use some included middleware
		Middleware(web.ShowErrorsMiddleware).     // ...
		Middleware((*Context).TestApiMiddleware). // use the Test version of the methods
		Middleware(web.StaticMiddlewareFromDir(http.Dir("static"), web.StaticOption{Prefix: "", IndexFile: "index.html"})).
		Post("/recipe", (*Context).PostRecipe).
		Get("/recipe/:id", (*Context).GetRecipe).
		Post("/search/", (*Context).SearchRecipe)
	return router
}