Skip to content

Commit

Permalink
Merge pull request #5 from qiangxue/master
Browse files Browse the repository at this point in the history
Added go-ozzo/ozzo-routing
  • Loading branch information
diyan committed Oct 30, 2016
2 parents a526ba0 + 67800a5 commit fe51bba
Showing 1 changed file with 50 additions and 6 deletions.
56 changes: 50 additions & 6 deletions README.md
Expand Up @@ -17,6 +17,7 @@ NOTE While code blocks are self-explained the list of PROs an CONs are highly op
- gin-gonic/gin
- go-macaron/macaron
- go-martini/martini
- go-ozzo/ozzo-routing
- gocraft/web
- goji/goji
- gorilla/mux
Expand All @@ -40,10 +41,10 @@ NOTE While code blocks are self-explained the list of PROs an CONs are highly op
- :thumbsdown: negroni, stdlib net/http does not dispatch request by HTTP verb (more boilerplate code)
- :thumbsdown: hoisie/web, zenazn/goji offers to use singletone istance of the server struct which is quite bad practice
- :question: goji/goji has quite unusual API to dispatch requests by HTTP verb but it's still more verbose than in echo, gin, julienschmidt/httprouter
- :thumbsup: echo, gin, julienschmidt/httprouter, zenazn/goji, goji/goji, pressly/chi handers are stronly typed
- :thumbsup: echo, gin, julienschmidt/httprouter, zenazn/goji, pressly/chi do dispatch requests by HTTP verb
- :thumbsup: echo, gin, zenazn/goji, pressly/chi support HTTP middleware
- :thumbsup: echo handers returns error value which could be handled in next middlewares in the chain
- :thumbsup: echo, gin, julienschmidt/httprouter, zenazn/goji, goji/goji, ozzo-routing, pressly/chi handers are stronly typed
- :thumbsup: echo, gin, julienschmidt/httprouter, zenazn/goji, ozzo-routing, pressly/chi do dispatch requests by HTTP verb
- :thumbsup: echo, gin, zenazn/goji, ozzo-routing, pressly/chi support HTTP middleware
- :thumbsup: echo, ozzo-routing handers returns error value which could be handled in next middlewares in the chain
- :question: julienschmidt/httprouter does not support HTTP middleware, gorilla/handlers are recommended instead
- :question: goji/goji keeps handler interface standard but it's quite verbose to type
- FYI labstack/echo has own router, supports most handler / middleware APIs
Expand Down Expand Up @@ -110,6 +111,15 @@ g.HandleFunc(pat.Get("/"), func (w http.ResponseWriter, r *http.Request) { ...
g.HandleFuncC(pat.Get("/"), func (ctx context.Context, w http.ResponseWriter, r *http.Request) { ...
```
### go-ozzo/ozzo-routing
https://godoc.org/github.com/go-ozzo/ozzo-routing#RouteGroup.Get
```go
func (r *RouteGroup) Get(path string, handlers ...Handler) *Route
type Handler func(*routing.Context) error

r.Get("/", func(c *routing.Context) error { ...
```
### hoisie/web
https://godoc.org/github.com/hoisie/web#Get
```go
Expand Down Expand Up @@ -164,7 +174,7 @@ TODO add godoc urls
- :thumbsdown: martini, hoisie/web, macaron are not considered, their handers are not strongly typed due to reflective dependency injection
- :thumbsdown: zenazn/goji handler and middleware are not strongly typed to emulate function overload
- :thumbsdown: gin has "func (c *Context) Next()" function that visible to all handlers but must be called only inside middleware
- :thumbsup: echo, goji/goji, pressly/chi, negroni has strongly typed middleware with reasonable signatures
- :thumbsup: echo, goji/goji, ozzo-routing, pressly/chi, negroni has strongly typed middleware with reasonable signatures
- :question: negroni uses quite unusual signature for middleware. Why? I have only one explanation at this point. Author decide to avoid usage of higher-order function, so it would be easier to grasp for not-experienced developers
- TODO gocraft/web PROs and CONs that related to the middleware API
Expand Down Expand Up @@ -220,6 +230,18 @@ func Middleware(inner goji.Handler) goji.Handler {
}
```
### go-ozzo/ozzo-routing
```go
// middlewares and handers share the same type "Handler" in ozzo-routing

func Middleware(c *routing.Context) error {
// do some stuff before
err := c.Next()
// do some stuff after
return err
}
```
### labstack/echo
```go
type MiddlewareFunc func(HandlerFunc) HandlerFunc
Expand Down Expand Up @@ -307,6 +329,15 @@ m.Get("/", func(r render.Render) {
})
```
### go-ozzo/ozzo-routing
```go
// Context.Write will write the data in the format determined by the content negotiation middleware (included)
r.Get("/", func(c *routing.Context) error {
// if Write returns an error, the framework will render HTTP 500 response by default
return c.Write(Greeting{Hello: "world"})
})
```
### gocraft/web + corneldamian/json-binding than mentioned in README
TODO Review implementation in https://github.com/corneldamian/json-binding/blob/master/response.go#L47
Expand Down Expand Up @@ -414,6 +445,19 @@ m.Post("/", binding.Bind(Greeting{}), func(g Greeting) (int, string) {
})
```
### go-ozzo/ozzo-routing
```go
r.Post("/", func(c *routing.Context) error {
var g Greeting
// Context.Read will read the data in the format specified by the "Content-Type" header
if err := c.Read(&g); err != nil {
return err
}
c.Response.WriteHeader(http.StatusCreated)
return nil
})
```
### gocraft/web + corneldamian/json-binding than mentioned in README
TODO Review implementation in https://github.com/corneldamian/json-binding/blob/master/request.go#L56
Expand All @@ -437,4 +481,4 @@ c.Post("/", func(w http.ResponseWriter, r *http.Request) {
}
render.NoContent(w, r)
})
```
```

0 comments on commit fe51bba

Please sign in to comment.