-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.go
42 lines (35 loc) · 1.06 KB
/
action.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package mxgo
import "reflect"
type Action struct {
CtrlName ControllerInterface
FuncName string
}
func NewAction(ctrlName ControllerInterface,funcName string) Action{
action := &Action{}
action.CtrlName = ctrlName
action.FuncName = funcName
return action;
}
func ErrorAction(errorCode int,errorMsg string) Action{
action := &Action{}
action.CtrlName = &ErrorController{}
action.FuncName = "Handle"
return action;
}
func (action *Action)Execute(mxGo *MxGoApp){
mxGo.Fm.BeforeAction(nil)
ctrlValue := reflect.ValueOf(action.CtrlName).Elem()
mxLog.Debug("ACTION:",ctrlValue,action.FuncName)
if ctrlFunc := ctrlValue.MethodByName(action.FuncName);ctrlFunc.IsValid() {
reflect.TypeOf(ctrlFunc)
request := ctrlValue.FieldByName("Request")
if parseFormFunc := request.MethodByName("ParseForm");parseFormFunc.IsValid() {
parseFormFunc.Call(make([]reflect.Value,0))//Call ParseForm Func
}
formValues := request.FieldByName("Form").Elem()
params := make([]reflect.Value,0)
result := ctrlFunc.Call(params)[0]
mxLog.Debug(result)
}
mxGo.Fm.AfterAction(nil)
}