From e2ee2a8a79ae22f23758d8fc19449a7ae95d3a4b Mon Sep 17 00:00:00 2001 From: astaxie Date: Fri, 16 Oct 2015 23:44:11 +0800 Subject: [PATCH 1/3] update the status cide --- g_appcode.go | 27 ++++++++++++++------------- g_controllers.go | 15 ++++++++------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/g_appcode.go b/g_appcode.go index 5607e77..dffbb69 100644 --- a/g_appcode.go +++ b/g_appcode.go @@ -362,12 +362,12 @@ func getTableObjects(tableNames []string, db *sql.DB, dbTransformer DbTransforme // and fill in Table struct func (*MysqlDB) GetConstraints(db *sql.DB, table *Table, blackList map[string]bool) { rows, err := db.Query( - `SELECT + `SELECT c.constraint_type, u.column_name, u.referenced_table_schema, u.referenced_table_name, referenced_column_name, u.ordinal_position FROM - information_schema.table_constraints c + information_schema.table_constraints c INNER JOIN - information_schema.key_column_usage u ON c.constraint_name = u.constraint_name + information_schema.key_column_usage u ON c.constraint_name = u.constraint_name WHERE c.table_schema = database() AND c.table_name = ? AND u.table_schema = database() AND u.table_name = ?`, table.Name, table.Name) // u.position_in_unique_constraint, @@ -412,9 +412,9 @@ func (mysqlDB *MysqlDB) GetColumns(db *sql.DB, table *Table, blackList map[strin // retrieve columns colDefRows, _ := db.Query( `SELECT - column_name, data_type, column_type, is_nullable, column_default, extra + column_name, data_type, column_type, is_nullable, column_default, extra FROM - information_schema.columns + information_schema.columns WHERE table_schema = database() AND table_name = ?`, table.Name) @@ -537,7 +537,7 @@ func (*PostgresDB) GetTableNames(db *sql.DB) (tables []string) { // GetConstraints for PostgreSQL func (*PostgresDB) GetConstraints(db *sql.DB, table *Table, blackList map[string]bool) { rows, err := db.Query( - `SELECT + `SELECT c.constraint_type, u.column_name, cu.table_catalog AS referenced_table_catalog, @@ -545,13 +545,13 @@ func (*PostgresDB) GetConstraints(db *sql.DB, table *Table, blackList map[string cu.column_name AS referenced_column_name, u.ordinal_position FROM - information_schema.table_constraints c + information_schema.table_constraints c INNER JOIN information_schema.key_column_usage u ON c.constraint_name = u.constraint_name INNER JOIN information_schema.constraint_column_usage cu ON cu.constraint_name = c.constraint_name WHERE - c.table_catalog = current_database() AND c.table_schema = 'public' AND c.table_name = $1 + c.table_catalog = current_database() AND c.table_schema = 'public' AND c.table_name = $1 AND u.table_catalog = current_database() AND u.table_schema = 'public' AND u.table_name = $2`, table.Name, table.Name) // u.position_in_unique_constraint, if err != nil { @@ -606,7 +606,7 @@ func (postgresDB *PostgresDB) GetColumns(db *sql.DB, table *Table, blackList map column_default, '' AS extra FROM - information_schema.columns + information_schema.columns WHERE table_catalog = current_database() AND table_schema = 'public' AND table_name = $1`, table.Name) @@ -1167,14 +1167,15 @@ func (c *{{ctrlName}}Controller) URLMapping() { // @Title Post // @Description create {{ctrlName}} // @Param body body models.{{ctrlName}} true "body for {{ctrlName}} content" -// @Success 200 {int} models.{{ctrlName}}.Id +// @Success 201 {int} models.{{ctrlName}} // @Failure 403 body is empty // @router / [post] func (c *{{ctrlName}}Controller) Post() { var v models.{{ctrlName}} json.Unmarshal(c.Ctx.Input.RequestBody, &v) - if id, err := models.Add{{ctrlName}}(&v); err == nil { - c.Data["json"] = map[string]int64{"id": id} + if _, err := models.Add{{ctrlName}}(&v); err == nil { + c.Ctx.Output.SetStatus(201) + c.Data["json"] = v } else { c.Data["json"] = err.Error() } @@ -1208,7 +1209,7 @@ func (c *{{ctrlName}}Controller) GetOne() { // @Param limit query string false "Limit the size of result set. Must be an integer" // @Param offset query string false "Start position of result set. Must be an integer" // @Success 200 {object} models.{{ctrlName}} -// @Failure 403 +// @Failure 403 // @router / [get] func (c *{{ctrlName}}Controller) GetAll() { var fields []string diff --git a/g_controllers.go b/g_controllers.go index 30bc86c..a832679 100644 --- a/g_controllers.go +++ b/g_controllers.go @@ -88,7 +88,7 @@ func (c *{{controllerName}}Controller) URLMapping() { // @Title Post // @Description create {{controllerName}} // @Param body body models.{{controllerName}} true "body for {{controllerName}} content" -// @Success 200 {int} models.{{controllerName}}.Id +// @Success 201 {object} models.{{controllerName}} // @Failure 403 body is empty // @router / [post] func (c *{{controllerName}}Controller) Post() { @@ -128,7 +128,7 @@ func (c *{{controllerName}}Controller) GetAll() { // @Failure 403 :id is not int // @router /:id [put] func (c *{{controllerName}}Controller) Put() { - + } // @Title Delete @@ -138,7 +138,7 @@ func (c *{{controllerName}}Controller) Put() { // @Failure 403 id is empty // @router /:id [delete] func (c *{{controllerName}}Controller) Delete() { - + } ` @@ -170,14 +170,15 @@ func (c *{{controllerName}}Controller) URLMapping() { // @Title Post // @Description create {{controllerName}} // @Param body body models.{{controllerName}} true "body for {{controllerName}} content" -// @Success 200 {int} models.{{controllerName}}.Id +// @Success 201 {int} models.{{controllerName}} // @Failure 403 body is empty // @router / [post] func (c *{{controllerName}}Controller) Post() { var v models.{{controllerName}} json.Unmarshal(c.Ctx.Input.RequestBody, &v) - if id, err := models.Add{{controllerName}}(&v); err == nil { - c.Data["json"] = map[string]int64{"id": id} + if _, err := models.Add{{controllerName}}(&v); err == nil { + c.Ctx.Output.SetStatus(201) + c.Data["json"] = v } else { c.Data["json"] = err.Error() } @@ -211,7 +212,7 @@ func (c *{{controllerName}}Controller) GetOne() { // @Param limit query string false "Limit the size of result set. Must be an integer" // @Param offset query string false "Start position of result set. Must be an integer" // @Success 200 {object} models.{{controllerName}} -// @Failure 403 +// @Failure 403 // @router / [get] func (c *{{controllerName}}Controller) GetAll() { var fields []string From f2bbe62bce3676a519a07737622edb4b45817cd6 Mon Sep 17 00:00:00 2001 From: FarYoung Date: Wed, 25 Nov 2015 22:24:10 +0800 Subject: [PATCH 2/3] add post and put json invalid fomart filter --- g_appcode.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/g_appcode.go b/g_appcode.go index dffbb69..52d2a62 100644 --- a/g_appcode.go +++ b/g_appcode.go @@ -1172,10 +1172,13 @@ func (c *{{ctrlName}}Controller) URLMapping() { // @router / [post] func (c *{{ctrlName}}Controller) Post() { var v models.{{ctrlName}} - json.Unmarshal(c.Ctx.Input.RequestBody, &v) - if _, err := models.Add{{ctrlName}}(&v); err == nil { - c.Ctx.Output.SetStatus(201) - c.Data["json"] = v + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil { + if _, err := models.Add{{ctrlName}}(&v); err == nil { + c.Ctx.Output.SetStatus(201) + c.Data["json"] = v + } else { + c.Data["json"] = err.Error() + } } else { c.Data["json"] = err.Error() } @@ -1273,9 +1276,12 @@ func (c *{{ctrlName}}Controller) Put() { idStr := c.Ctx.Input.Params[":id"] id, _ := strconv.Atoi(idStr) v := models.{{ctrlName}}{Id: id} - json.Unmarshal(c.Ctx.Input.RequestBody, &v) - if err := models.Update{{ctrlName}}ById(&v); err == nil { - c.Data["json"] = "OK" + if err := json.Unmarshal(c.Ctx.Input.RequestBody, &v); err == nil { + if err := models.Update{{ctrlName}}ById(&v); err == nil { + c.Data["json"] = "OK" + } else { + c.Data["json"] = err.Error() + } } else { c.Data["json"] = err.Error() } From 69c2bb9058a7bb47900b6caa0749d5df31eb96b8 Mon Sep 17 00:00:00 2001 From: Yanyi Wu Date: Fri, 27 Nov 2015 11:42:14 +0800 Subject: [PATCH 3/3] Fix bug about issue #143 --- pack.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pack.go b/pack.go index 7ce6b73..20f18f0 100644 --- a/pack.go +++ b/pack.go @@ -455,7 +455,7 @@ func packDirectory(excludePrefix []string, excludeSuffix []string, func isBeegoProject(thePath string) bool { fh, _ := os.Open(thePath) fis, _ := fh.Readdir(-1) - regex := regexp.MustCompile(`(?s)package main.*?import.*?\(.*?"github.com/astaxie/beego".*?\).*func main()`) + regex := regexp.MustCompile(`(?s)package main.*?import.*?\(.*?github.com/astaxie/beego".*?\).*func main()`) for _, fi := range fis { if fi.IsDir() == false && strings.HasSuffix(fi.Name(), ".go") { data, err := ioutil.ReadFile(path.Join(thePath, fi.Name()))