This is an automated email from the ASF dual-hosted git repository.
dehowef pushed a commit to branch ageviewer_go
in repository https://gitbox.apache.org/repos/asf/age.git
The following commit(s) were added to refs/heads/ageviewer_go by this push:
new 2b6beffc Refactor session middleware and add constant for database
name (#941)
2b6beffc is described below
commit 2b6beffcb6a719abe9b120b24a99b5f714182b18
Author: Moiz Ibrar <[email protected]>
AuthorDate: Tue May 23 02:30:42 2023 +0500
Refactor session middleware and add constant for database name (#941)
---
backend/session/session.go | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)
diff --git a/backend/session/session.go b/backend/session/session.go
index 8fd7e7a0..8ccdfb35 100644
--- a/backend/session/session.go
+++ b/backend/session/session.go
@@ -1,20 +1,24 @@
package session
import (
+ "net/http"
+
"github.com/labstack/echo"
)
-func UserSessions() echo.MiddlewareFunc {
+const (
+ DatabaseName = "database"
+)
+func UserSessions() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
- sess, err := Store.Get(c.Request(), "database")
+ sess, err := Store.Get(c.Request(), DatabaseName)
if err != nil {
- return echo.NewHTTPError(400, err.Error())
+ return echo.NewHTTPError(http.StatusBadRequest,
err.Error())
}
- c.Set("database", sess)
+ c.Set(DatabaseName, sess)
return next(c)
}
}
-
}