Add multiple routes simultaneously

closes #329
This commit is contained in:
Adrian Brink 2018-02-26 14:02:03 +01:00 committed by rigelrozanski
parent 55730270e5
commit 40c3465ec5
2 changed files with 7 additions and 4 deletions

View File

@ -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

View File

@ -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)