Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Switching the default router from Httptreemux to Bone.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien Herfray committed Oct 5, 2015
1 parent 40506d4 commit 5948d8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Having a good cli interface, a simple init/exit process and your app injected au

Zest makes all that simple by aggregating well known and efficient packages. The `Classic` version also provides some default tools useful for most applications :
- [Gin](https://github.com/gin-gonic/gin) inspired logging, [CORS](https://github.com/rs/cors) (allowing all origins by default) and Recovery middlewares
- Pre-injected custom JSON renderer and [Httptreemux](https://github.com/dimfeld/httptreemux) router
- Pre-injected custom JSON renderer and [Bone](https://github.com/go-zoo/bone) router

## Installation

Expand Down Expand Up @@ -49,8 +49,8 @@ In the `New` version of Zest, the launch sequence only triggers the dependency i
The `RegisterSequence` and `InitSequence` arrays are empty.

In the `Classic` version, default register and init steps are provided:
- `classicRegister` which registers the default dependencies (Render, Httptreemux) in the injector.
- `classicInit` which initialize the Httptreemux router and the default middlewares in Negroni.
- `classicRegister` which registers the default dependencies (Render, Bone) in the injector.
- `classicInit` which initialize the Bone router and the default middlewares in Negroni.

In both versions, the exit sequence is empty.

Expand Down Expand Up @@ -89,7 +89,7 @@ In situation, it looks like that :
```go
var UnknownAPIError = &zest.APIError{Description: "An error occured. Please retry later.", ErrorCode: "UNKNOWN_ERROR"}

func (c *Controller) Handler(w http.ResponseWriter, r *http.Request, params map[string]string) {
func (c *Controller) Handler(w http.ResponseWriter, r *http.Request) {
result, err := c.m.Action()
if err != nil {
c.r.JSONError(w, http.StatusInternalServerError, UnknownAPIError, err)
Expand All @@ -108,7 +108,7 @@ func (c *Controller) Handler(w http.ResponseWriter, r *http.Request, params map[
package main

import (
"github.com/dimfeld/httptreemux"
"github.com/go-zoo/bone"
"github.com/solher/zest"
)

Expand All @@ -127,15 +127,15 @@ func main() {

func SetRoutes(z *zest.Zest) error {
d := &struct {
Router *httptreemux.TreeMux
Router *bone.Mux
Ctrl *Controller
}{}

if err := z.Injector.Get(d); err != nil {
return err
}

d.Router.GET("/", d.Ctrl.Handler)
d.Router.GetFunc("/", d.Ctrl.Handler)

return nil
}
Expand Down Expand Up @@ -165,7 +165,7 @@ func NewController(m *Model, r *zest.Render) *Controller {
return &Controller{m: m, r: r}
}

func (c *Controller) Handler(w http.ResponseWriter, r *http.Request, params map[string]string) {
func (c *Controller) Handler(w http.ResponseWriter, r *http.Request) {
result, err := c.m.Action()
if err != nil {
apiErr := &zest.APIError{Description: "An error occured. Please retry later.", ErrorCode: "UNKNOWN_ERROR"}
Expand Down
10 changes: 5 additions & 5 deletions zest.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

"github.com/codegangsta/cli"
"github.com/codegangsta/negroni"
"github.com/dimfeld/httptreemux"
"github.com/go-zoo/bone"
"github.com/rs/cors"
"github.com/solher/syringe"
)
Expand Down Expand Up @@ -65,8 +65,8 @@ func (z *Zest) Run() {
}

// Classic returns a new instance of Zest, with some default register and init steps:
// "classicRegister" which registers the default dependencies (Render, Httptreemux) in the injector.
// "classicInit" which initialize the Httptreemux router and the default middlewares in Negroni.
// "classicRegister" which registers the default dependencies (Render, Bone) in the injector.
// "classicInit" which initialize the Bone router and the default middlewares in Negroni.
func Classic() *Zest {
z := New()

Expand Down Expand Up @@ -148,13 +148,13 @@ func (z *Zest) exit(c *cli.Context) error {
}

func classicRegister(z *Zest) error {
z.Injector.Register(NewRender(), httptreemux.New())
z.Injector.Register(NewRender(), bone.New())

return nil
}

func classicInit(z *Zest) error {
d := &struct{ Router *httptreemux.TreeMux }{}
d := &struct{ Router *bone.Mux }{}

if err := z.Injector.Get(d); err != nil {
return err
Expand Down

0 comments on commit 5948d8f

Please sign in to comment.