beego:change ControllerComments exported
Showing
3 changed files
with
17 additions
and
17 deletions
| ... | @@ -40,10 +40,10 @@ var ( | ... | @@ -40,10 +40,10 @@ var ( |
| 40 | 40 | ||
| 41 | // store the comment for the controller method | 41 | // store the comment for the controller method |
| 42 | type ControllerComments struct { | 42 | type ControllerComments struct { |
| 43 | method string | 43 | Method string |
| 44 | router string | 44 | Router string |
| 45 | allowHTTPMethods []string | 45 | AllowHTTPMethods []string |
| 46 | params []map[string]string | 46 | Params []map[string]string |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | // Controller defines some basic http request handler operations, such as | 49 | // Controller defines some basic http request handler operations, such as | ... | ... |
| ... | @@ -69,23 +69,23 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat | ... | @@ -69,23 +69,23 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat |
| 69 | } | 69 | } |
| 70 | key := pkgpath + ":" + controllerName | 70 | key := pkgpath + ":" + controllerName |
| 71 | cc := ControllerComments{} | 71 | cc := ControllerComments{} |
| 72 | cc.method = funcName | 72 | cc.Method = funcName |
| 73 | cc.router = e1[0] | 73 | cc.Router = e1[0] |
| 74 | if len(e1) == 2 && e1[1] != "" { | 74 | if len(e1) == 2 && e1[1] != "" { |
| 75 | e1 = strings.SplitN(e1[1], " ", 2) | 75 | e1 = strings.SplitN(e1[1], " ", 2) |
| 76 | if len(e1) >= 1 { | 76 | if len(e1) >= 1 { |
| 77 | cc.allowHTTPMethods = strings.Split(strings.Trim(e1[0], "[]"), ",") | 77 | cc.AllowHTTPMethods = strings.Split(strings.Trim(e1[0], "[]"), ",") |
| 78 | } else { | 78 | } else { |
| 79 | cc.allowHTTPMethods = append(cc.allowHTTPMethods, "get") | 79 | cc.AllowHTTPMethods = append(cc.AllowHTTPMethods, "get") |
| 80 | } | 80 | } |
| 81 | } else { | 81 | } else { |
| 82 | cc.allowHTTPMethods = append(cc.allowHTTPMethods, "get") | 82 | cc.AllowHTTPMethods = append(cc.AllowHTTPMethods, "get") |
| 83 | } | 83 | } |
| 84 | if len(e1) == 2 && e1[1] != "" { | 84 | if len(e1) == 2 && e1[1] != "" { |
| 85 | keyval := strings.Split(strings.Trim(e1[1], "[]"), " ") | 85 | keyval := strings.Split(strings.Trim(e1[1], "[]"), " ") |
| 86 | for _, kv := range keyval { | 86 | for _, kv := range keyval { |
| 87 | kk := strings.Split(kv, ":") | 87 | kk := strings.Split(kv, ":") |
| 88 | cc.params = append(cc.params, map[string]string{strings.Join(kk[:len(kk)-1], ":"): kk[len(kk)-1]}) | 88 | cc.Params = append(cc.Params, map[string]string{strings.Join(kk[:len(kk)-1], ":"): kk[len(kk)-1]}) |
| 89 | } | 89 | } |
| 90 | } | 90 | } |
| 91 | genInfoList[key] = append(genInfoList[key], cc) | 91 | genInfoList[key] = append(genInfoList[key], cc) |
| ... | @@ -107,25 +107,25 @@ func genRouterCode() { | ... | @@ -107,25 +107,25 @@ func genRouterCode() { |
| 107 | for k, cList := range genInfoList { | 107 | for k, cList := range genInfoList { |
| 108 | for _, c := range cList { | 108 | for _, c := range cList { |
| 109 | allmethod := "nil" | 109 | allmethod := "nil" |
| 110 | if len(c.allowHTTPMethods) > 0 { | 110 | if len(c.AllowHTTPMethods) > 0 { |
| 111 | allmethod = "[]string{" | 111 | allmethod = "[]string{" |
| 112 | for _, m := range c.allowHTTPMethods { | 112 | for _, m := range c.AllowHTTPMethods { |
| 113 | allmethod += `"` + m + `",` | 113 | allmethod += `"` + m + `",` |
| 114 | } | 114 | } |
| 115 | allmethod = strings.TrimRight(allmethod, ",") + "}" | 115 | allmethod = strings.TrimRight(allmethod, ",") + "}" |
| 116 | } | 116 | } |
| 117 | params := "nil" | 117 | params := "nil" |
| 118 | if len(c.params) > 0 { | 118 | if len(c.Params) > 0 { |
| 119 | params = "[]map[string]string{" | 119 | params = "[]map[string]string{" |
| 120 | for _, p := range c.params { | 120 | for _, p := range c.Params { |
| 121 | for k, v := range p { | 121 | for k, v := range p { |
| 122 | params = params + `map[string]string{` + k + `:"` + v + `"},` | 122 | params = params + `map[string]string{` + k + `:"` + v + `"},` |
| 123 | } | 123 | } |
| 124 | } | 124 | } |
| 125 | params = strings.TrimRight(params, ",") + "}" | 125 | params = strings.TrimRight(params, ",") + "}" |
| 126 | } | 126 | } |
| 127 | globalinfo = globalinfo + fmt.Sprintln(`beego.GlobalControllerRouter["`+k+`"] = &ControllerComments{"`+ | 127 | globalinfo = globalinfo + fmt.Sprintln(`beego.GlobalControllerRouter["`+k+`"] = &beego.ControllerComments{"`+ |
| 128 | strings.TrimSpace(c.method)+`", "`+c.router+`", `+allmethod+", "+params+"}") | 128 | strings.TrimSpace(c.Method)+`", "`+c.Router+`", `+allmethod+", "+params+"}") |
| 129 | } | 129 | } |
| 130 | } | 130 | } |
| 131 | f.WriteString(strings.Replace(globalRouterTemplate, "{{.globalinfo}}", globalinfo, -1)) | 131 | f.WriteString(strings.Replace(globalRouterTemplate, "{{.globalinfo}}", globalinfo, -1)) | ... | ... |
| ... | @@ -185,7 +185,7 @@ func (p *ControllerRegistor) Include(cList ...ControllerInterface) { | ... | @@ -185,7 +185,7 @@ func (p *ControllerRegistor) Include(cList ...ControllerInterface) { |
| 185 | key := t.PkgPath() + ":" + t.Name() | 185 | key := t.PkgPath() + ":" + t.Name() |
| 186 | if comm, ok := GlobalControllerRouter[key]; ok { | 186 | if comm, ok := GlobalControllerRouter[key]; ok { |
| 187 | for _, a := range comm { | 187 | for _, a := range comm { |
| 188 | p.Add(a.router, c, strings.Join(a.allowHTTPMethods, ",")+":"+a.method) | 188 | p.Add(a.Router, c, strings.Join(a.AllowHTTPMethods, ",")+":"+a.Method) |
| 189 | } | 189 | } |
| 190 | } | 190 | } |
| 191 | } | 191 | } | ... | ... |
-
Please register or sign in to post a comment