mirror of
https://github.com/beego/bee.git
synced 2024-11-23 06:40:54 +00:00
commit
f0cd17dbb1
23
g_appcode.go
23
g_appcode.go
@ -985,6 +985,12 @@ func getPackagePath(curpath string) (packpath string) {
|
||||
ColorLog("[ERRO] Can't generate application code outside of GOPATH '%s'\n", gopath)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
if curpath == appsrcpath {
|
||||
ColorLog("[ERRO] Can't generate application code outside of application PATH \n")
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
packpath = strings.Join(strings.Split(curpath[len(appsrcpath)+1:], string(filepath.Separator)), "/")
|
||||
return
|
||||
}
|
||||
@ -1167,14 +1173,18 @@ 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 := 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()
|
||||
}
|
||||
@ -1272,12 +1282,15 @@ 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 := 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()
|
||||
}
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
@ -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()
|
||||
}
|
||||
|
2
pack.go
2
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()))
|
||||
|
Loading…
Reference in New Issue
Block a user