Skip to content

Commit

Permalink
Add buffalo example
Browse files Browse the repository at this point in the history
  • Loading branch information
rs committed Jan 23, 2018
1 parent eabcc6a commit 1c02c2b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ The server now runs on `localhost:8080`:
* [Negroni](https://github.com/codegangsta/negroni): [examples/negroni/server.go](https://github.com/rs/cors/blob/master/examples/negroni/server.go)
* [Alice](https://github.com/justinas/alice): [examples/alice/server.go](https://github.com/rs/cors/blob/master/examples/alice/server.go)
* [HttpRouter](https://github.com/julienschmidt/httprouter): [examples/httprouter/server.go](https://github.com/rs/cors/blob/master/examples/httprouter/server.go)
* [Gorilla](http://www.gorillatoolkit.org/pkg/mux): [examples/gorilla/server.go](https://github.com/rs/cors/blob/master/examples/gorilla/server.go)
* [Buffalo](https://gobuffalo.io): [examples/buffalo/server.go](https://github.com/rs/cors/blob/master/examples/buffalo/server.go)

## Parameters

Expand Down
36 changes: 36 additions & 0 deletions examples/buffalo/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import (
"log"

"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/buffalo/render"
"github.com/rs/cors"
)

var r *render.Engine

func init() {
r = render.New(render.Options{})
}

func main() {
app := App()
if err := app.Serve(); err != nil {
log.Fatal(err)
}
}

func App() *buffalo.App {
app := buffalo.New(buffalo.Options{
PreWares: []buffalo.PreWare{cors.Default().Handler},
})

app.GET("/", HomeHandler)

return app
}

func HomeHandler(c buffalo.Context) error {
return c.Render(200, r.JSON(map[string]string{"message": "Welcome to Buffalo!"}))
}

0 comments on commit 1c02c2b

Please sign in to comment.