Merge pull request #511 from cosmos/adrian/multiple_routes
WIP: Add multiple routes simultaneously
This commit is contained in:
commit
2a3990d713
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
// Router provides handlers for each transaction type.
|
||||
type Router interface {
|
||||
AddRoute(r string, h sdk.Handler)
|
||||
AddRoute(r string, h sdk.Handler) (rtr Router)
|
||||
Route(path string) (h sdk.Handler)
|
||||
}
|
||||
|
||||
|
@ -34,11 +34,13 @@ func NewRouter() *router {
|
|||
var isAlpha = regexp.MustCompile(`^[a-zA-Z]+$`).MatchString
|
||||
|
||||
// AddRoute - TODO add description
|
||||
func (rtr *router) AddRoute(r string, h sdk.Handler) {
|
||||
func (rtr *router) AddRoute(r string, h sdk.Handler) Router {
|
||||
if !isAlpha(r) {
|
||||
panic("route expressions can only contain alphanumeric characters")
|
||||
}
|
||||
rtr.routes = append(rtr.routes, route{r, h})
|
||||
|
||||
return rtr
|
||||
}
|
||||
|
||||
// Route - TODO add description
|
||||
|
|
|
@ -53,8 +53,9 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB) *BasecoinApp {
|
|||
|
||||
// add handlers
|
||||
coinKeeper := bank.NewCoinKeeper(app.accountMapper)
|
||||
app.Router().AddRoute("bank", bank.NewHandler(coinKeeper))
|
||||
app.Router().AddRoute("sketchy", sketchy.NewHandler())
|
||||
app.Router().
|
||||
AddRoute("bank", bank.NewHandler(coinKeeper)).
|
||||
AddRoute("sketchy", sketchy.NewHandler())
|
||||
|
||||
// initialize BaseApp
|
||||
app.SetTxDecoder(app.txDecoder)
|
||||
|
|
Loading…
Reference in New Issue