mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 18:37:05 +00:00
implement a way to add controller functions as handlers with the existing rules respected but it's a bit dirty I will change the implementation and move the mvc2 to mvc and make the api builder's PartyFunc to be a critical part of the controller and the mvc2.Mvc bind values should be also respected to the controller and more
Former-commit-id: e452a916da80d886535b8ae9625d0ba8e2b58d6e
This commit is contained in:
@@ -28,22 +28,25 @@ func testBinderFunc(ctx iris.Context) testUserStruct {
|
||||
|
||||
// service
|
||||
type (
|
||||
testService interface {
|
||||
// these TestService and TestServiceImpl could be in lowercase, unexported
|
||||
// but the `Say` method should be exported however we have those exported
|
||||
// because of the controller handler test.
|
||||
TestService interface {
|
||||
Say(string) string
|
||||
}
|
||||
testServiceImpl struct {
|
||||
TestServiceImpl struct {
|
||||
prefix string
|
||||
}
|
||||
)
|
||||
|
||||
func (s *testServiceImpl) Say(message string) string {
|
||||
func (s *TestServiceImpl) Say(message string) string {
|
||||
return s.prefix + " " + message
|
||||
}
|
||||
|
||||
var (
|
||||
// binders, as user-defined
|
||||
testBinderFuncUserStruct = testBinderFunc
|
||||
testBinderService = &testServiceImpl{prefix: "say"}
|
||||
testBinderService = &TestServiceImpl{prefix: "say"}
|
||||
testBinderFuncParam = func(ctx iris.Context) string {
|
||||
return ctx.Params().Get("param")
|
||||
}
|
||||
@@ -56,7 +59,7 @@ var (
|
||||
}
|
||||
|
||||
// just one input arg, the service which is binded by the #2 service binder.
|
||||
testConsumeServiceHandler = func(service testService) string {
|
||||
testConsumeServiceHandler = func(service TestService) string {
|
||||
return service.Say("something")
|
||||
}
|
||||
// just one input arg, a standar string which is binded by the #3 func(ctx) any binder.
|
||||
|
||||
Reference in New Issue
Block a user