ab08aa9c by astaxie

MethodByName

1 parent 7c610ee7
...@@ -94,8 +94,8 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM ...@@ -94,8 +94,8 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM
94 } 94 }
95 } 95 }
96 } 96 }
97 reflectVal := reflect.Indirect(reflect.ValueOf(c)) 97 reflectVal := reflect.ValueOf(c)
98 t := reflectVal.Type() 98 t := reflect.Indirect(reflectVal).Type()
99 methods := make(map[string]string) 99 methods := make(map[string]string)
100 if len(mappingMethods) > 0 { 100 if len(mappingMethods) > 0 {
101 semi := strings.Split(mappingMethods[0], ";") 101 semi := strings.Split(mappingMethods[0], ";")
...@@ -107,7 +107,7 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM ...@@ -107,7 +107,7 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM
107 comma := strings.Split(colon[0], ",") 107 comma := strings.Split(colon[0], ",")
108 for _, m := range comma { 108 for _, m := range comma {
109 if m == "*" || inSlice(strings.ToLower(m), HTTPMETHOD) { 109 if m == "*" || inSlice(strings.ToLower(m), HTTPMETHOD) {
110 if val := reflectVal.FieldByName(colon[1]); val.IsValid() { 110 if val := reflectVal.MethodByName(colon[1]); val.IsValid() {
111 methods[strings.ToLower(m)] = colon[1] 111 methods[strings.ToLower(m)] = colon[1]
112 } else { 112 } else {
113 panic(colon[1] + " method don't exist in the controller " + t.Name()) 113 panic(colon[1] + " method don't exist in the controller " + t.Name())
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!