From 48817da755372618ac81e58ac0118b0766f86e16 Mon Sep 17 00:00:00 2001 From: MingZong Date: Fri, 1 Apr 2016 17:49:17 +0800 Subject: [PATCH] Complete controller modification --- g_controller.go | 5 +++-- g_structure.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/g_controller.go b/g_controller.go index ff36e80..9a3f631 100644 --- a/g_controller.go +++ b/g_controller.go @@ -146,6 +146,7 @@ var controllerModelTpl = `package {{packageName}} import ( "{{pkgPath}}/models" + "{{pkgPath}}/structures" "encoding/json" "errors" "strconv" @@ -174,7 +175,7 @@ func (c *{{controllerName}}Controller) URLMapping() { // @Failure 403 body is empty // @router / [post] func (c *{{controllerName}}Controller) Post() { - var v models.{{controllerName}} + var v structures.{{controllerName}} json.Unmarshal(c.Ctx.Input.RequestBody, &v) if _, err := models.Add{{controllerName}}(&v); err == nil { c.Ctx.Output.SetStatus(201) @@ -275,7 +276,7 @@ func (c *{{controllerName}}Controller) GetAll() { func (c *{{controllerName}}Controller) Put() { idStr := c.Ctx.Input.Param(":id") id, _ := strconv.ParseInt(idStr, 0, 64) - v := models.{{controllerName}}{Id: id} + v := structures.{{controllerName}}{Id: id} json.Unmarshal(c.Ctx.Input.RequestBody, &v) if err := models.Update{{controllerName}}ById(&v); err == nil { c.Data["json"] = "OK" diff --git a/g_structure.go b/g_structure.go index bfe950d..3879010 100644 --- a/g_structure.go +++ b/g_structure.go @@ -1,4 +1,4 @@ -// Copyright 2013 Dylan LYU (mingzong.lyu@gmail.com) +// Copyright 2016 Dylan LYU (mingzong.lyu@gmail.com) // // Licensed under the Apache License, Version 2.0 (the "License"): you may // not use this file except in compliance with the License. You may obtain