7c610ee7 by astaxie

fix reflect find methodByName

1 parent 23deaedd
...@@ -94,7 +94,8 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM ...@@ -94,7 +94,8 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM
94 } 94 }
95 } 95 }
96 } 96 }
97 t := reflect.Indirect(reflect.ValueOf(c)).Type() 97 reflectVal := reflect.Indirect(reflect.ValueOf(c))
98 t := reflectVal.Type()
98 methods := make(map[string]string) 99 methods := make(map[string]string)
99 if len(mappingMethods) > 0 { 100 if len(mappingMethods) > 0 {
100 semi := strings.Split(mappingMethods[0], ";") 101 semi := strings.Split(mappingMethods[0], ";")
...@@ -106,7 +107,7 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM ...@@ -106,7 +107,7 @@ func (p *ControllerRegistor) Add(pattern string, c ControllerInterface, mappingM
106 comma := strings.Split(colon[0], ",") 107 comma := strings.Split(colon[0], ",")
107 for _, m := range comma { 108 for _, m := range comma {
108 if m == "*" || inSlice(strings.ToLower(m), HTTPMETHOD) { 109 if m == "*" || inSlice(strings.ToLower(m), HTTPMETHOD) {
109 if _, ok := t.MethodByName(colon[1]); ok { 110 if val := reflectVal.FieldByName(colon[1]); val.IsValid() {
110 methods[strings.ToLower(m)] = colon[1] 111 methods[strings.ToLower(m)] = colon[1]
111 } else { 112 } else {
112 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!