Fixed a bug where a struct would have old values in it
This commit is contained in:
@ -1,16 +1,17 @@
|
||||
package crud
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.kolaente.de/konrad/list/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// CreateWeb is the handler to create an object
|
||||
func (c *WebHandler) CreateWeb(ctx echo.Context) error {
|
||||
// Re-initialize our model
|
||||
c.CObject.Empty()
|
||||
p := reflect.ValueOf(c.CObject).Elem()
|
||||
p.Set(reflect.Zero(p.Type()))
|
||||
|
||||
// Get the object
|
||||
if err := ctx.Bind(&c.CObject); err != nil {
|
||||
@ -57,8 +58,6 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
|
||||
return echo.NewHTTPError(http.StatusNotFound, "The namespace name cannot be empty.")
|
||||
}
|
||||
|
||||
fmt.Println(err)
|
||||
|
||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
|
@ -4,10 +4,15 @@ import (
|
||||
"git.kolaente.de/konrad/list/models"
|
||||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// UpdateWeb is the webhandler to update an object
|
||||
func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
|
||||
// Re-initialize our model
|
||||
p := reflect.ValueOf(c.CObject).Elem()
|
||||
p.Set(reflect.Zero(p.Type()))
|
||||
|
||||
// Get the object
|
||||
if err := ctx.Bind(&c.CObject); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "No or invalid model provided.")
|
||||
|
Reference in New Issue
Block a user