-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from yoyofx/dev
add action filters and MVC route template. v1.5.0.pre-release
- Loading branch information
Showing
16 changed files
with
452 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package contollers | ||
|
||
import ( | ||
"fmt" | ||
"github.com/yoyofx/yoyogo/WebFramework/Mvc" | ||
) | ||
|
||
type TestActionFilter struct { | ||
} | ||
|
||
func (f *TestActionFilter) OnActionExecuting(context Mvc.ActionFilterContext) bool { | ||
fmt.Println("TestActionFilter OnActionExecuting") | ||
return false | ||
} | ||
|
||
func (f *TestActionFilter) OnActionExecuted(context Mvc.ActionFilterContext) { | ||
fmt.Println("TestActionFilter OnActionExecuted") | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package Test | ||
|
||
import ( | ||
"fmt" | ||
"github.com/magiconair/properties/assert" | ||
"github.com/yoyofx/yoyogo/WebFramework/Mvc" | ||
"testing" | ||
) | ||
|
||
type TestActionFilter struct { | ||
} | ||
|
||
func (f *TestActionFilter) OnActionExecuting(context Mvc.ActionFilterContext) bool { | ||
fmt.Println("TestActionFilter OnActionExecuted") | ||
return true | ||
} | ||
|
||
func (f *TestActionFilter) OnActionExecuted(context Mvc.ActionFilterContext) { | ||
fmt.Println("TestActionFilter OnActionExecuted") | ||
} | ||
|
||
func Test_Filter(t *testing.T) { | ||
|
||
chain := Mvc.NewActionFilterChain("u*/get*", &TestActionFilter{}) | ||
|
||
assert.Equal(t, chain.MatchPath("user/getuser"), true) | ||
|
||
assert.Equal(t, chain.MatchPath("user/get/1"), true) | ||
|
||
assert.Equal(t, chain.MatchPath("/user/get/1"), false) | ||
|
||
assert.Equal(t, chain.MatchPath("v1/user/get/1"), false) | ||
|
||
filter := chain.MatchFilter("user/get/1") | ||
assert.Equal(t, filter != nil, true) | ||
c := Mvc.ActionFilterContext{} | ||
assert.Equal(t, filter.OnActionExecuting(c), true) | ||
filter.OnActionExecuted(c) | ||
|
||
chain1 := Mvc.NewActionFilterChain("v1/user/info", &TestActionFilter{}) | ||
assert.Equal(t, chain1.MatchPath("v1/user/info"), true) | ||
|
||
} |
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,29 @@ | ||
package Test | ||
|
||
import ( | ||
"github.com/magiconair/properties/assert" | ||
"github.com/yoyofx/yoyogo/WebFramework/Mvc" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func Test_MvcTemplate(t *testing.T) { | ||
url := "v1/usercontroller/register" | ||
template := Mvc.NewRouteTemplate("v1/{controller}/{action}") | ||
assert.Equal(t, template.GetControllerIndex(), 1) | ||
assert.Equal(t, template.GetActionIndex(), 2) | ||
|
||
assert.Equal(t, template.Match(strings.Split(url, "/")), true) | ||
assert.Equal(t, template.ControllerName, "usercontroller") | ||
assert.Equal(t, template.ActionName, "register") | ||
|
||
template1 := Mvc.NewRouteTemplate("api/v1/{controller}/{action}") | ||
assert.Equal(t, template1.GetControllerIndex(), 2) | ||
assert.Equal(t, template1.GetActionIndex(), 3) | ||
|
||
assert.Equal(t, template1.Match(strings.Split(url, "/")), false) | ||
assert.Equal(t, template1.Match(strings.Split("api/"+url, "/")), true) | ||
assert.Equal(t, template1.ControllerName, "usercontroller") | ||
assert.Equal(t, template1.ActionName, "register") | ||
|
||
} |
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
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
Oops, something went wrong.