Close all sessions in a defer
This commit is contained in:
parent
a897a6def6
commit
588abb7370
|
@ -48,6 +48,12 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
|
||||||
|
|
||||||
// Create the db session
|
// Create the db session
|
||||||
s := config.SessionFactory()
|
s := config.SessionFactory()
|
||||||
|
defer func() {
|
||||||
|
err = s.Close()
|
||||||
|
if err != nil {
|
||||||
|
config.LoggingProvider.Errorf("Could not close session: %s", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Check rights
|
// Check rights
|
||||||
canCreate, err := currentStruct.CanCreate(s, currentAuth)
|
canCreate, err := currentStruct.CanCreate(s, currentAuth)
|
||||||
|
@ -73,11 +79,6 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
|
||||||
return HandleHTTPError(err, ctx)
|
return HandleHTTPError(err, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Close()
|
|
||||||
if err != nil {
|
|
||||||
return HandleHTTPError(err, ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = ctx.JSON(http.StatusCreated, currentStruct)
|
err = ctx.JSON(http.StatusCreated, currentStruct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return HandleHTTPError(err, ctx)
|
return HandleHTTPError(err, ctx)
|
||||||
|
|
|
@ -48,6 +48,12 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
|
||||||
|
|
||||||
// Create the db session
|
// Create the db session
|
||||||
s := config.SessionFactory()
|
s := config.SessionFactory()
|
||||||
|
defer func() {
|
||||||
|
err = s.Close()
|
||||||
|
if err != nil {
|
||||||
|
config.LoggingProvider.Errorf("Could not close session: %s", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
canDelete, err := currentStruct.CanDelete(s, currentAuth)
|
canDelete, err := currentStruct.CanDelete(s, currentAuth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -71,11 +77,6 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
|
||||||
return HandleHTTPError(err, ctx)
|
return HandleHTTPError(err, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Close()
|
|
||||||
if err != nil {
|
|
||||||
return HandleHTTPError(err, ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = ctx.JSON(http.StatusOK, message{"Successfully deleted."})
|
err = ctx.JSON(http.StatusOK, message{"Successfully deleted."})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return HandleHTTPError(err, ctx)
|
return HandleHTTPError(err, ctx)
|
||||||
|
|
|
@ -81,6 +81,12 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
||||||
|
|
||||||
// Create the db session
|
// Create the db session
|
||||||
s := config.SessionFactory()
|
s := config.SessionFactory()
|
||||||
|
defer func() {
|
||||||
|
err = s.Close()
|
||||||
|
if err != nil {
|
||||||
|
config.LoggingProvider.Errorf("Could not close session: %s", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
// Search
|
// Search
|
||||||
search := ctx.QueryParam("s")
|
search := ctx.QueryParam("s")
|
||||||
|
@ -113,11 +119,6 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
||||||
return HandleHTTPError(err, ctx)
|
return HandleHTTPError(err, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Close()
|
|
||||||
if err != nil {
|
|
||||||
return HandleHTTPError(err, ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = ctx.JSON(http.StatusOK, result)
|
err = ctx.JSON(http.StatusOK, result)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return HandleHTTPError(err, ctx)
|
return HandleHTTPError(err, ctx)
|
||||||
|
|
|
@ -44,6 +44,12 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
|
||||||
|
|
||||||
// Create the db session
|
// Create the db session
|
||||||
s := config.SessionFactory()
|
s := config.SessionFactory()
|
||||||
|
defer func() {
|
||||||
|
err = s.Close()
|
||||||
|
if err != nil {
|
||||||
|
config.LoggingProvider.Errorf("Could not close session: %s", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
canRead, maxRight, err := currentStruct.CanRead(s, currentAuth)
|
canRead, maxRight, err := currentStruct.CanRead(s, currentAuth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -74,11 +80,6 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
|
||||||
return HandleHTTPError(err, ctx)
|
return HandleHTTPError(err, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Close()
|
|
||||||
if err != nil {
|
|
||||||
return HandleHTTPError(err, ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = ctx.JSON(http.StatusOK, currentStruct)
|
err = ctx.JSON(http.StatusOK, currentStruct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return HandleHTTPError(err, ctx)
|
return HandleHTTPError(err, ctx)
|
||||||
|
|
|
@ -49,6 +49,12 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
|
||||||
|
|
||||||
// Create the db session
|
// Create the db session
|
||||||
s := config.SessionFactory()
|
s := config.SessionFactory()
|
||||||
|
defer func() {
|
||||||
|
err = s.Close()
|
||||||
|
if err != nil {
|
||||||
|
config.LoggingProvider.Errorf("Could not close session: %s", err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
canUpdate, err := currentStruct.CanUpdate(s, currentAuth)
|
canUpdate, err := currentStruct.CanUpdate(s, currentAuth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -73,11 +79,6 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
|
||||||
return HandleHTTPError(err, ctx)
|
return HandleHTTPError(err, ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Close()
|
|
||||||
if err != nil {
|
|
||||||
return HandleHTTPError(err, ctx)
|
|
||||||
}
|
|
||||||
|
|
||||||
err = ctx.JSON(http.StatusOK, currentStruct)
|
err = ctx.JSON(http.StatusOK, currentStruct)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return HandleHTTPError(err, ctx)
|
return HandleHTTPError(err, ctx)
|
||||||
|
|
Loading…
Reference in New Issue