-
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 #30 from maxzhang1985/dev
action invoke complated . and render result format with content-type …
- Loading branch information
Showing
31 changed files
with
365 additions
and
194 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
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,21 @@ | ||
package Controller | ||
|
||
import ( | ||
"github.com/maxzhang1985/yoyogo/Context" | ||
"github.com/maxzhang1985/yoyogo/Utils" | ||
"reflect" | ||
) | ||
|
||
type ActionExecutorInParam struct { | ||
ActionParamTypes []reflect.Type | ||
MethodInovker *Utils.MethodCaller | ||
} | ||
|
||
type ActionExecutorContext struct { | ||
ControllerName string | ||
ActionName string | ||
|
||
Controller IController | ||
Context *Context.HttpContext | ||
In *ActionExecutorInParam | ||
} |
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,63 @@ | ||
package Controller | ||
|
||
import ( | ||
"github.com/maxzhang1985/yoyogo/Context" | ||
"github.com/maxzhang1985/yoyogo/Utils" | ||
"reflect" | ||
) | ||
|
||
type ActionMethodExecutor struct { | ||
} | ||
|
||
func NewActionMethodExecutor() ActionMethodExecutor { | ||
return ActionMethodExecutor{} | ||
} | ||
|
||
func (actionExecutor ActionMethodExecutor) Execute(ctx *ActionExecutorContext) interface{} { | ||
if ctx.Controller != nil { | ||
if ctx.In.MethodInovker == nil { | ||
ctx.In.MethodInovker = Utils.NewMethodCaller(ctx.Controller, ctx.ActionName) | ||
ctx.In.ActionParamTypes = ctx.In.MethodInovker.GetParamTypes() | ||
} | ||
|
||
values := getParamValues(ctx.In.ActionParamTypes, ctx.Context) | ||
returns := ctx.In.MethodInovker.Invoke(values...) | ||
if len(returns) > 0 { | ||
responseData := returns[0] | ||
return responseData | ||
} | ||
|
||
} | ||
|
||
return nil | ||
} | ||
|
||
func getParamValues(paramTypes []reflect.Type, ctx *Context.HttpContext) []interface{} { | ||
if len(paramTypes) == 0 { | ||
return nil | ||
} | ||
values := make([]interface{}, len(paramTypes)) | ||
for index, paramType := range paramTypes { | ||
if paramType.Kind() == reflect.Ptr { | ||
paramType = paramType.Elem() | ||
} | ||
if paramType.Kind() == reflect.Struct { | ||
switch paramType.Name() { | ||
case "HttpContext": | ||
values[index] = ctx | ||
default: | ||
if paramType.NumField() > 0 && paramType.Field(0).Name == "RequestBody" { | ||
reqBindingData := reflect.New(paramType).Interface() | ||
_ = ctx.Bind(reqBindingData) | ||
values[index] = reqBindingData | ||
} | ||
} | ||
} | ||
} | ||
|
||
return values | ||
} | ||
|
||
func RequestParamTypeConvertFunc(index int, paramType reflect.Type, ctx *Context.HttpContext) { | ||
|
||
} |
Oops, something went wrong.