diff --git a/apiapp.go b/apiapp.go index f5a921b..ec6bb95 100644 --- a/apiapp.go +++ b/apiapp.go @@ -309,7 +309,7 @@ func (o *ObjectController) Post() { json.Unmarshal(o.Ctx.Input.RequestBody, &ob) objectid := models.AddOne(ob) o.Data["json"] = map[string]string{"ObjectId": objectid} - o.ServeJson() + o.ServeJSON() } // @Title Get @@ -323,12 +323,12 @@ func (o *ObjectController) Get() { if objectId != "" { ob, err := models.GetOne(objectId) if err != nil { - o.Data["json"] = err + o.Data["json"] = err.Error() } else { o.Data["json"] = ob } } - o.ServeJson() + o.ServeJSON() } // @Title GetAll @@ -339,7 +339,7 @@ func (o *ObjectController) Get() { func (o *ObjectController) GetAll() { obs := models.GetAll() o.Data["json"] = obs - o.ServeJson() + o.ServeJSON() } // @Title update @@ -356,11 +356,11 @@ func (o *ObjectController) Put() { err := models.Update(objectId, ob.Score) if err != nil { - o.Data["json"] = err + o.Data["json"] = err.Error() } else { o.Data["json"] = "update success!" } - o.ServeJson() + o.ServeJSON() } // @Title delete @@ -373,7 +373,7 @@ func (o *ObjectController) Delete() { objectId := o.Ctx.Input.Params[":objectId"] models.Delete(objectId) o.Data["json"] = "delete success!" - o.ServeJson() + o.ServeJSON() } ` @@ -402,7 +402,7 @@ func (u *UserController) Post() { json.Unmarshal(u.Ctx.Input.RequestBody, &user) uid := models.AddUser(user) u.Data["json"] = map[string]string{"uid": uid} - u.ServeJson() + u.ServeJSON() } // @Title Get @@ -412,7 +412,7 @@ func (u *UserController) Post() { func (u *UserController) GetAll() { users := models.GetAllUsers() u.Data["json"] = users - u.ServeJson() + u.ServeJSON() } // @Title Get @@ -426,12 +426,12 @@ func (u *UserController) Get() { if uid != "" { user, err := models.GetUser(uid) if err != nil { - u.Data["json"] = err + u.Data["json"] = err.Error() } else { u.Data["json"] = user } } - u.ServeJson() + u.ServeJSON() } // @Title update @@ -448,12 +448,12 @@ func (u *UserController) Put() { json.Unmarshal(u.Ctx.Input.RequestBody, &user) uu, err := models.UpdateUser(uid, &user) if err != nil { - u.Data["json"] = err + u.Data["json"] = err.Error() } else { u.Data["json"] = uu } } - u.ServeJson() + u.ServeJSON() } // @Title delete @@ -466,7 +466,7 @@ func (u *UserController) Delete() { uid := u.GetString(":uid") models.DeleteUser(uid) u.Data["json"] = "delete success!" - u.ServeJson() + u.ServeJSON() } // @Title login @@ -484,7 +484,7 @@ func (u *UserController) Login() { } else { u.Data["json"] = "user not exist" } - u.ServeJson() + u.ServeJSON() } // @Title logout @@ -493,7 +493,7 @@ func (u *UserController) Login() { // @router /logout [get] func (u *UserController) Logout() { u.Data["json"] = "logout success" - u.ServeJson() + u.ServeJSON() } ` diff --git a/g.go b/g.go index 2d7e80e..e0eb265 100644 --- a/g.go +++ b/g.go @@ -166,8 +166,8 @@ func generateCode(cmd *Command, args []string) int { upsql := "" downsql := "" if fields != "" { - upsql = `m.Sql("CREATE TABLE ` + mname + "(" + generateSQLFromFields(fields.String()) + `)");` - downsql = `m.Sql("DROP TABLE ` + "`" + mname + "`" + `")` + upsql = `m.SQL("CREATE TABLE ` + mname + "(" + generateSQLFromFields(fields.String()) + `)");` + downsql = `m.SQL("DROP TABLE ` + "`" + mname + "`" + `")` } generateMigration(mname, upsql, downsql, curpath) case "controller": diff --git a/g_appcode.go b/g_appcode.go index f3a9d63..8e54902 100644 --- a/g_appcode.go +++ b/g_appcode.go @@ -1188,7 +1188,7 @@ func (c *{{ctrlName}}Controller) Post() { } else { c.Data["json"] = err.Error() } - c.ServeJson() + c.ServeJSON() } // @Title Get @@ -1206,7 +1206,7 @@ func (c *{{ctrlName}}Controller) GetOne() { } else { c.Data["json"] = v } - c.ServeJson() + c.ServeJSON() } // @Title Get All @@ -1254,7 +1254,7 @@ func (c *{{ctrlName}}Controller) GetAll() { kv := strings.Split(cond, ":") if len(kv) != 2 { c.Data["json"] = errors.New("Error: invalid query key/value pair") - c.ServeJson() + c.ServeJSON() return } k, v := kv[0], kv[1] @@ -1268,7 +1268,7 @@ func (c *{{ctrlName}}Controller) GetAll() { } else { c.Data["json"] = l } - c.ServeJson() + c.ServeJSON() } // @Title Update @@ -1291,7 +1291,7 @@ func (c *{{ctrlName}}Controller) Put() { } else { c.Data["json"] = err.Error() } - c.ServeJson() + c.ServeJSON() } // @Title Delete @@ -1308,7 +1308,7 @@ func (c *{{ctrlName}}Controller) Delete() { } else { c.Data["json"] = err.Error() } - c.ServeJson() + c.ServeJSON() } ` ROUTER_TPL = `// @APIVersion 1.0.0 diff --git a/g_controllers.go b/g_controllers.go index a832679..57f2e02 100644 --- a/g_controllers.go +++ b/g_controllers.go @@ -182,7 +182,7 @@ func (c *{{controllerName}}Controller) Post() { } else { c.Data["json"] = err.Error() } - c.ServeJson() + c.ServeJSON() } // @Title Get @@ -200,7 +200,7 @@ func (c *{{controllerName}}Controller) GetOne() { } else { c.Data["json"] = v } - c.ServeJson() + c.ServeJSON() } // @Title Get All @@ -248,7 +248,7 @@ func (c *{{controllerName}}Controller) GetAll() { kv := strings.Split(cond, ":") if len(kv) != 2 { c.Data["json"] = errors.New("Error: invalid query key/value pair") - c.ServeJson() + c.ServeJSON() return } k, v := kv[0], kv[1] @@ -262,7 +262,7 @@ func (c *{{controllerName}}Controller) GetAll() { } else { c.Data["json"] = l } - c.ServeJson() + c.ServeJSON() } // @Title Update @@ -282,7 +282,7 @@ func (c *{{controllerName}}Controller) Put() { } else { c.Data["json"] = err.Error() } - c.ServeJson() + c.ServeJSON() } // @Title Delete @@ -299,6 +299,6 @@ func (c *{{controllerName}}Controller) Delete() { } else { c.Data["json"] = err.Error() } - c.ServeJson() + c.ServeJSON() } ` diff --git a/g_docs.go b/g_docs.go index ea2ef00..6da36ce 100644 --- a/g_docs.go +++ b/g_docs.go @@ -52,7 +52,7 @@ const ( ) var rootapi swagger.ResourceListing -var apilist map[string]*swagger.ApiDeclaration +var apilist map[string]*swagger.APIDeclaration func init() { if beego.EnableDocs { @@ -64,14 +64,14 @@ func init() { if err != nil { beego.Error(err) } - beego.GlobalDocApi["Root"] = rootapi + beego.GlobalDocAPI["Root"] = rootapi for k, v := range apilist { - for i, a := range v.Apis { + for i, a := range v.APIs { a.Path = urlReplace(k + a.Path) - v.Apis[i] = a + v.APIs[i] = a } v.BasePath = BasePath - beego.GlobalDocApi[strings.Trim(k, "/")] = v + beego.GlobalDocAPI[strings.Trim(k, "/")] = v } } } @@ -102,8 +102,8 @@ const ( var pkgCache map[string]bool //pkg:controller:function:comments comments: key:value var controllerComments map[string]string var importlist map[string]string -var apilist map[string]*swagger.ApiDeclaration -var controllerList map[string][]swagger.Api +var apilist map[string]*swagger.APIDeclaration +var controllerList map[string][]swagger.API var modelsList map[string]map[string]swagger.Model var rootapi swagger.ResourceListing @@ -111,8 +111,8 @@ func init() { pkgCache = make(map[string]bool) controllerComments = make(map[string]string) importlist = make(map[string]string) - apilist = make(map[string]*swagger.ApiDeclaration) - controllerList = make(map[string][]swagger.Api) + apilist = make(map[string]*swagger.APIDeclaration) + controllerList = make(map[string][]swagger.API) modelsList = make(map[string]map[string]swagger.Model) } @@ -133,19 +133,19 @@ func generateDocs(curpath string) { for _, c := range f.Comments { for _, s := range strings.Split(c.Text(), "\n") { if strings.HasPrefix(s, "@APIVersion") { - rootapi.ApiVersion = strings.TrimSpace(s[len("@APIVersion"):]) + rootapi.APIVersion = strings.TrimSpace(s[len("@APIVersion"):]) } else if strings.HasPrefix(s, "@Title") { rootapi.Infos.Title = strings.TrimSpace(s[len("@Title"):]) } else if strings.HasPrefix(s, "@Description") { rootapi.Infos.Description = strings.TrimSpace(s[len("@Description"):]) } else if strings.HasPrefix(s, "@TermsOfServiceUrl") { - rootapi.Infos.TermsOfServiceUrl = strings.TrimSpace(s[len("@TermsOfServiceUrl"):]) + rootapi.Infos.TermsOfServiceURL = strings.TrimSpace(s[len("@TermsOfServiceUrl"):]) } else if strings.HasPrefix(s, "@Contact") { rootapi.Infos.Contact = strings.TrimSpace(s[len("@Contact"):]) } else if strings.HasPrefix(s, "@License") { rootapi.Infos.License = strings.TrimSpace(s[len("@License"):]) } else if strings.HasPrefix(s, "@LicenseUrl") { - rootapi.Infos.LicenseUrl = strings.TrimSpace(s[len("@LicenseUrl"):]) + rootapi.Infos.LicenseURL = strings.TrimSpace(s[len("@LicenseUrl"):]) } } } @@ -172,7 +172,7 @@ func generateDocs(curpath string) { case *ast.CallExpr: if selname := pp.Fun.(*ast.SelectorExpr).Sel.String(); selname == "NSNamespace" { s, params := analisysNewNamespace(pp) - subapi := swagger.ApiRef{Path: s} + subapi := swagger.APIRef{Path: s} controllerName := "" for _, sp := range params { switch pp := sp.(type) { @@ -185,7 +185,7 @@ func generateDocs(curpath string) { if v, ok := controllerComments[controllerName]; ok { subapi.Description = v } - rootapi.Apis = append(rootapi.Apis, subapi) + rootapi.APIs = append(rootapi.APIs, subapi) } else if selname == "NSInclude" { analisysNSInclude(f, pp) } @@ -233,12 +233,12 @@ func analisysNewNamespace(ce *ast.CallExpr) (first string, others []ast.Expr) { func analisysNSInclude(baseurl string, ce *ast.CallExpr) string { cname := "" - a := &swagger.ApiDeclaration{} - a.ApiVersion = rootapi.ApiVersion + a := &swagger.APIDeclaration{} + a.APIVersion = rootapi.APIVersion a.SwaggerVersion = swagger.SwaggerVersion a.ResourcePath = baseurl a.Produces = []string{"application/json", "application/xml", "text/plain", "text/html"} - a.Apis = make([]swagger.Api, 0) + a.APIs = make([]swagger.API, 0) a.Models = make(map[string]swagger.Model) for _, p := range ce.Args { x := p.(*ast.UnaryExpr).X.(*ast.CompositeLit).Type.(*ast.SelectorExpr) @@ -246,15 +246,15 @@ func analisysNSInclude(baseurl string, ce *ast.CallExpr) string { cname = v + x.Sel.Name } if apis, ok := controllerList[cname]; ok { - if len(a.Apis) > 0 { - a.Apis = append(a.Apis, apis...) + if len(a.APIs) > 0 { + a.APIs = append(a.APIs, apis...) } else { - a.Apis = apis + a.APIs = apis } } if models, ok := modelsList[cname]; ok { for _, m := range models { - a.Models[m.Id] = m + a.Models[m.ID] = m } } } @@ -355,7 +355,7 @@ func isSystemPackage(pkgpath string) bool { // parse the func comments func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpath string) error { - innerapi := swagger.Api{} + innerapi := swagger.API{} opts := swagger.Operation{} if comments != nil && comments.List != nil { for _, c := range comments.List { @@ -369,9 +369,9 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat innerapi.Path = e1[0] if len(e1) == 2 && e1[1] != "" { e1 = strings.SplitN(e1[1], " ", 2) - opts.HttpMethod = strings.ToUpper(strings.Trim(e1[0], "[]")) + opts.HTTPMethod = strings.ToUpper(strings.Trim(e1[0], "[]")) } else { - opts.HttpMethod = "GET" + opts.HTTPMethod = "GET" } } else if strings.HasPrefix(t, "@Title") { opts.Nickname = strings.TrimSpace(t[len("@Title"):]) @@ -490,7 +490,7 @@ func parserComments(comments *ast.CommentGroup, funcName, controllerName, pkgpat if _, ok := controllerList[pkgpath+controllerName]; ok { controllerList[pkgpath+controllerName] = append(controllerList[pkgpath+controllerName], innerapi) } else { - controllerList[pkgpath+controllerName] = make([]swagger.Api, 1) + controllerList[pkgpath+controllerName] = make([]swagger.API, 1) controllerList[pkgpath+controllerName][0] = innerapi } } @@ -561,7 +561,7 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Model, realType if !ok { continue } - m.Id = k + m.ID = k if st.Fields.List != nil { m.Properties = make(map[string]swagger.ModelProperty) for _, field := range st.Fields.List { @@ -635,7 +635,7 @@ func getModel(str string) (pkgpath, objectname string, m swagger.Model, realType } } } - if m.Id == "" { + if m.ID == "" { ColorLog("can't find the object: %v", str) os.Exit(1) } diff --git a/g_migration.go b/g_migration.go index 7e3fefe..d0d296d 100644 --- a/g_migration.go +++ b/g_migration.go @@ -79,13 +79,13 @@ func init() { // Run the migrations func (m *{{StructName}}) Up() { - // use m.Sql("CREATE TABLE ...") to make schema update + // use m.SQL("CREATE TABLE ...") to make schema update {{UpSQL}} } // Reverse the migrations func (m *{{StructName}}) Down() { - // use m.Sql("DROP TABLE ...") to reverse schema update + // use m.SQL("DROP TABLE ...") to reverse schema update {{DownSQL}} } ` diff --git a/g_scaffold.go b/g_scaffold.go index 1d0c239..a9df9d8 100644 --- a/g_scaffold.go +++ b/g_scaffold.go @@ -28,8 +28,8 @@ func generateScaffold(sname, fields, crupath, driver, conn string) { upsql := "" downsql := "" if fields != "" { - upsql = `m.Sql("CREATE TABLE ` + sname + "(" + generateSQLFromFields(fields) + `)");` - downsql = `m.Sql("DROP TABLE ` + "`" + sname + "`" + `")` + upsql = `m.SQL("CREATE TABLE ` + sname + "(" + generateSQLFromFields(fields) + `)");` + downsql = `m.SQL("DROP TABLE ` + "`" + sname + "`" + `")` } generateMigration(sname, upsql, downsql, crupath) } @@ -48,12 +48,12 @@ func generateSQLFromFields(fields string) string { for i, v := range fds { kv := strings.SplitN(v, ":", 2) if len(kv) != 2 { - ColorLog("[ERRO] the filds format is wrong. should key:type,key:type " + v) + ColorLog("[ERRO] the fields format is wrong. should key:type,key:type " + v + "\n") return "" } typ, tag := getSqlType(kv[1]) if typ == "" { - ColorLog("[ERRO] the filds format is wrong. should key:type,key:type " + v) + ColorLog("[ERRO] the fields format is wrong. should key:type,key:type " + v + "\n") return "" } if i == 0 && strings.ToLower(kv[0]) != "id" {