1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-20 03:17:04 +00:00

create a new package, name it as hero, I was thinking super or superb but hero is better name for what it does - the goal is to split the new 'mvc handlers' from the mvc system because they are not the same, users should know that they can use these type of rich binded handlers without controllers as well, like a normal handler and that I implemented here, the old files exist on the mvc package but will be removed at the next commit, I have to decide if we want type aliases for Result or no

Former-commit-id: cb775edc72bedc88aeab4c5a6de6bfc6bd56fae2
This commit is contained in:
Gerasimos (Makis) Maropoulos
2017-12-25 20:05:32 +02:00
parent 4ab889da5f
commit 46505f62db
43 changed files with 2680 additions and 20 deletions

48
hero/param_test.go Normal file
View File

@@ -0,0 +1,48 @@
package hero
import (
"testing"
"github.com/kataras/iris/context"
)
func TestPathParams(t *testing.T) {
got := ""
h := New()
handler := h.Handler(func(firstname string, lastname string) {
got = firstname + lastname
})
h.Register(func(ctx context.Context) func() string { return func() string { return "" } })
handlerWithOther := h.Handler(func(f func() string, firstname string, lastname string) {
got = f() + firstname + lastname
})
handlerWithOtherBetweenThem := h.Handler(func(firstname string, f func() string, lastname string) {
got = f() + firstname + lastname
})
ctx := context.NewContext(nil)
ctx.Params().Set("firstname", "Gerasimos")
ctx.Params().Set("lastname", "Maropoulos")
handler(ctx)
expected := "GerasimosMaropoulos"
if got != expected {
t.Fatalf("expected the params 'firstname' + 'lastname' to be '%s' but got '%s'", expected, got)
}
got = ""
handlerWithOther(ctx)
expected = "GerasimosMaropoulos"
if got != expected {
t.Fatalf("expected the params 'firstname' + 'lastname' to be '%s' but got '%s'", expected, got)
}
got = ""
handlerWithOtherBetweenThem(ctx)
expected = "GerasimosMaropoulos"
if got != expected {
t.Fatalf("expected the params 'firstname' + 'lastname' to be '%s' but got '%s'", expected, got)
}
}