-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Former-commit-id: 953df27468e3905e557bb1f6a97ea431cb60f6a6
- Loading branch information
Showing
6 changed files
with
85 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
_examples/routing/dynamic-path/same-pattern-different-func/use-global/main.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main // #1552 | ||
|
||
import ( | ||
"github.com/kataras/iris/v12" | ||
) | ||
|
||
func main() { | ||
app := newApp() | ||
app.Listen(":8080") | ||
} | ||
|
||
func newApp() *iris.Application { | ||
app := iris.New() | ||
|
||
app.UseGlobal(middleware("first")) | ||
app.UseGlobal(middleware("second")) | ||
app.DoneGlobal(onDone) | ||
|
||
app.Get("/{name prefix(one)}", handler("first route")) | ||
app.Get("/{name prefix(two)}", handler("second route")) | ||
app.Get("/{name prefix(three)}", handler("third route")) | ||
|
||
return app | ||
} | ||
|
||
func middleware(str string) iris.Handler { | ||
return func(ctx iris.Context) { | ||
ctx.Writef("Called %s middleware\n", str) | ||
ctx.Next() | ||
} | ||
} | ||
|
||
func handler(str string) iris.Handler { | ||
return func(ctx iris.Context) { | ||
ctx.Writef("%s\n", str) | ||
ctx.Next() // or ignroe that and use app.SetRegisterRules. | ||
} | ||
} | ||
|
||
func onDone(ctx iris.Context) { | ||
ctx.Writef("Called done: %s", ctx.Params().Get("name")) | ||
} |
25 changes: 25 additions & 0 deletions
25
_examples/routing/dynamic-path/same-pattern-different-func/use-global/main_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/kataras/iris/v12/httptest" | ||
) | ||
|
||
func TestSamePatternDifferentFuncUseGlobal(t *testing.T) { | ||
app := newApp() | ||
e := httptest.New(t, app) | ||
|
||
expectedResultFmt := "Called first middleware\nCalled second middleware\n%s\nCalled done: %s" | ||
tests := map[string]string{ | ||
"/one-num": "first route", | ||
"/two-num": "second route", | ||
"/three-num": "third route", | ||
} | ||
|
||
for path, mainBody := range tests { | ||
result := fmt.Sprintf(expectedResultFmt, mainBody, path[1:]) | ||
e.GET(path).Expect().Status(httptest.StatusOK).Body().Equal(result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters