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
|
||||
s := config.SessionFactory()
|
||||
defer func() {
|
||||
err = s.Close()
|
||||
if err != nil {
|
||||
config.LoggingProvider.Errorf("Could not close session: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Check rights
|
||||
canCreate, err := currentStruct.CanCreate(s, currentAuth)
|
||||
|
@ -73,11 +79,6 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
|
|||
return HandleHTTPError(err, ctx)
|
||||
}
|
||||
|
||||
err = s.Close()
|
||||
if err != nil {
|
||||
return HandleHTTPError(err, ctx)
|
||||
}
|
||||
|
||||
err = ctx.JSON(http.StatusCreated, currentStruct)
|
||||
if err != nil {
|
||||
return HandleHTTPError(err, ctx)
|
||||
|
|
|
@ -48,6 +48,12 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
|
|||
|
||||
// Create the db session
|
||||
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)
|
||||
if err != nil {
|
||||
|
@ -71,11 +77,6 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
|
|||
return HandleHTTPError(err, ctx)
|
||||
}
|
||||
|
||||
err = s.Close()
|
||||
if err != nil {
|
||||
return HandleHTTPError(err, ctx)
|
||||
}
|
||||
|
||||
err = ctx.JSON(http.StatusOK, message{"Successfully deleted."})
|
||||
if err != nil {
|
||||
return HandleHTTPError(err, ctx)
|
||||
|
|
|
@ -81,6 +81,12 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
|||
|
||||
// Create the db session
|
||||
s := config.SessionFactory()
|
||||
defer func() {
|
||||
err = s.Close()
|
||||
if err != nil {
|
||||
config.LoggingProvider.Errorf("Could not close session: %s", err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Search
|
||||
search := ctx.QueryParam("s")
|
||||
|
@ -113,11 +119,6 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
|||
return HandleHTTPError(err, ctx)
|
||||
}
|
||||
|
||||
err = s.Close()
|
||||
if err != nil {
|
||||
return HandleHTTPError(err, ctx)
|
||||
}
|
||||
|
||||
err = ctx.JSON(http.StatusOK, result)
|
||||
if err != nil {
|
||||
return HandleHTTPError(err, ctx)
|
||||
|
|
|
@ -44,6 +44,12 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
|
|||
|
||||
// Create the db session
|
||||
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)
|
||||
if err != nil {
|
||||
|
@ -74,11 +80,6 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
|
|||
return HandleHTTPError(err, ctx)
|
||||
}
|
||||
|
||||
err = s.Close()
|
||||
if err != nil {
|
||||
return HandleHTTPError(err, ctx)
|
||||
}
|
||||
|
||||
err = ctx.JSON(http.StatusOK, currentStruct)
|
||||
if err != nil {
|
||||
return HandleHTTPError(err, ctx)
|
||||
|
|
|
@ -49,6 +49,12 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
|
|||
|
||||
// Create the db session
|
||||
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)
|
||||
if err != nil {
|
||||
|
@ -73,11 +79,6 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
|
|||
return HandleHTTPError(err, ctx)
|
||||
}
|
||||
|
||||
err = s.Close()
|
||||
if err != nil {
|
||||
return HandleHTTPError(err, ctx)
|
||||
}
|
||||
|
||||
err = ctx.JSON(http.StatusOK, currentStruct)
|
||||
if err != nil {
|
||||
return HandleHTTPError(err, ctx)
|
||||
|
|
Loading…
Reference in New Issue