detached 76277bd

Middleware detect-lang disabled if lang=X is set in the session storage

commit
76277bdaaaf3048cf288376d4d917f5727e13fce
author
bnema · · 2023-09-04 19:36 UTC
parent
249d4fc
signature
unsigned
4 files · +31 -0
M go.mod +4 -0
@@ -17,6 +17,9 @@ require (
1717 github.com/docker/go-units v0.5.0 // indirect
1818 github.com/gogo/protobuf v1.3.2 // indirect
1919 github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
20+ github.com/gorilla/context v1.1.1 // indirect
21+ github.com/gorilla/securecookie v1.1.1 // indirect
22+ github.com/gorilla/sessions v1.2.1 // indirect
2023 github.com/opencontainers/go-digest v1.0.0 // indirect
2124 github.com/opencontainers/image-spec v1.0.2 // indirect
2225 github.com/pkg/errors v0.9.1 // indirect
@@ -26,6 +29,7 @@ require (
2629 )
2730
2831 require (
32+ github.com/labstack/echo-contrib v0.15.0
2933 github.com/labstack/gommon v0.4.0 // indirect
3034 github.com/mattn/go-colorable v0.1.13 // indirect
3135 github.com/mattn/go-isatty v0.0.19 // indirect
@@ -17,6 +17,9 @@ require (
17 github.com/docker/go-units v0.5.0 // indirect17 github.com/docker/go-units v0.5.0 // indirect
18 github.com/gogo/protobuf v1.3.2 // indirect18 github.com/gogo/protobuf v1.3.2 // indirect
19 github.com/golang-jwt/jwt v3.2.2+incompatible // indirect19 github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
20+ github.com/gorilla/context v1.1.1 // indirect
21+ github.com/gorilla/securecookie v1.1.1 // indirect
22+ github.com/gorilla/sessions v1.2.1 // indirect
20 github.com/opencontainers/go-digest v1.0.0 // indirect23 github.com/opencontainers/go-digest v1.0.0 // indirect
21 github.com/opencontainers/image-spec v1.0.2 // indirect24 github.com/opencontainers/image-spec v1.0.2 // indirect
22 github.com/pkg/errors v0.9.1 // indirect25 github.com/pkg/errors v0.9.1 // indirect
@@ -26,6 +29,7 @@ require (
26 )29 )
27 30
28 require (31 require (
32+ github.com/labstack/echo-contrib v0.15.0
29 github.com/labstack/gommon v0.4.0 // indirect33 github.com/labstack/gommon v0.4.0 // indirect
30 github.com/mattn/go-colorable v0.1.13 // indirect34 github.com/mattn/go-colorable v0.1.13 // indirect
31 github.com/mattn/go-isatty v0.0.19 // indirect35 github.com/mattn/go-isatty v0.0.19 // indirect
M go.sum +8 -0 generated file: collapsed
M internal/http/middlewares/detect-lang.go +8 -0
@@ -3,6 +3,7 @@ package middlewares
33 import (
44 "strings"
55
6+ "github.com/labstack/echo-contrib/session"
67 "github.com/labstack/echo/v4"
78 )
89
@@ -19,6 +20,13 @@ func LanguageDetectionMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
1920 }
2021
2122 func detectCurrentLanguage(c echo.Context) string {
23+ // Check if the lang key is set in the session storage
24+ sess, _ := session.Get("session", c) // Assuming you have a session named "session"
25+ if langValue, ok := sess.Values["lang"]; ok {
26+ return langValue.(string) // Return the lang value from the session storage
27+ }
28+
29+ // If lang key is not set, proceed with "Accept-Language" header detection
2230 header := c.Request().Header.Get("Accept-Language")
2331 if strings.Contains(header, "fr") {
2432 return "fr"
@@ -3,6 +3,7 @@ package middlewares
3 import (3 import (
4 "strings"4 "strings"
5 5
6+ "github.com/labstack/echo-contrib/session"
6 "github.com/labstack/echo/v4"7 "github.com/labstack/echo/v4"
7 )8 )
8 9
@@ -19,6 +20,13 @@ func LanguageDetectionMiddleware(next echo.HandlerFunc) echo.HandlerFunc {
19 }20 }
20 21
21 func detectCurrentLanguage(c echo.Context) string {22 func detectCurrentLanguage(c echo.Context) string {
23+ // Check if the lang key is set in the session storage
24+ sess, _ := session.Get("session", c) // Assuming you have a session named "session"
25+ if langValue, ok := sess.Values["lang"]; ok {
26+ return langValue.(string) // Return the lang value from the session storage
27+ }
28+
29+ // If lang key is not set, proceed with "Accept-Language" header detection
22 header := c.Request().Header.Get("Accept-Language")30 header := c.Request().Header.Get("Accept-Language")
23 if strings.Contains(header, "fr") {31 if strings.Contains(header, "fr") {
24 return "fr"32 return "fr"
M logs/app.log +11 -0
@@ -48,3 +48,14 @@
4848 {"level":"warn","time":"2023-09-04T14:51:10+02:00","message":"Server will shutdown in 5 seconds press ENTER to cancel"}
4949 {"level":"info","time":"2023-09-04T14:51:15+02:00","message":"Server shutdown"}
5050 {"level":"info","time":"2023-09-04T17:18:16+02:00","message":"Server is listening on port 1323"}
51+{"level":"info","time":"2023-09-04T21:36:24+02:00","message":"Server is listening on port 1323"}
52+{"level":"info","time":"2023-09-04T21:36:24+02:00","message":"Server is listening on port 1323"}
53+{"level":"fatal","error":"listen tcp :1323: bind: address already in use","time":"2023-09-04T21:36:24+02:00","message":"Failed to start the server"}
54+{"level":"info","time":"2023-09-04T21:36:24+02:00","message":"Server is listening on port 1323"}
55+{"level":"fatal","error":"listen tcp :1323: bind: address already in use","time":"2023-09-04T21:36:24+02:00","message":"Failed to start the server"}
56+{"level":"info","time":"2023-09-04T21:36:25+02:00","message":"Server is listening on port 1323"}
57+{"level":"fatal","error":"listen tcp :1323: bind: address already in use","time":"2023-09-04T21:36:25+02:00","message":"Failed to start the server"}
58+{"level":"info","time":"2023-09-04T21:36:25+02:00","message":"Server is listening on port 1323"}
59+{"level":"fatal","error":"listen tcp :1323: bind: address already in use","time":"2023-09-04T21:36:25+02:00","message":"Failed to start the server"}
60+{"level":"info","time":"2023-09-04T21:36:25+02:00","message":"Server is listening on port 1323"}
61+{"level":"fatal","error":"listen tcp :1323: bind: address already in use","time":"2023-09-04T21:36:25+02:00","message":"Failed to start the server"}
@@ -48,3 +48,14 @@
48 {"level":"warn","time":"2023-09-04T14:51:10+02:00","message":"Server will shutdown in 5 seconds press ENTER to cancel"}48 {"level":"warn","time":"2023-09-04T14:51:10+02:00","message":"Server will shutdown in 5 seconds press ENTER to cancel"}
49 {"level":"info","time":"2023-09-04T14:51:15+02:00","message":"Server shutdown"}49 {"level":"info","time":"2023-09-04T14:51:15+02:00","message":"Server shutdown"}
50 {"level":"info","time":"2023-09-04T17:18:16+02:00","message":"Server is listening on port 1323"}50 {"level":"info","time":"2023-09-04T17:18:16+02:00","message":"Server is listening on port 1323"}
51+{"level":"info","time":"2023-09-04T21:36:24+02:00","message":"Server is listening on port 1323"}
52+{"level":"info","time":"2023-09-04T21:36:24+02:00","message":"Server is listening on port 1323"}
53+{"level":"fatal","error":"listen tcp :1323: bind: address already in use","time":"2023-09-04T21:36:24+02:00","message":"Failed to start the server"}
54+{"level":"info","time":"2023-09-04T21:36:24+02:00","message":"Server is listening on port 1323"}
55+{"level":"fatal","error":"listen tcp :1323: bind: address already in use","time":"2023-09-04T21:36:24+02:00","message":"Failed to start the server"}
56+{"level":"info","time":"2023-09-04T21:36:25+02:00","message":"Server is listening on port 1323"}
57+{"level":"fatal","error":"listen tcp :1323: bind: address already in use","time":"2023-09-04T21:36:25+02:00","message":"Failed to start the server"}
58+{"level":"info","time":"2023-09-04T21:36:25+02:00","message":"Server is listening on port 1323"}
59+{"level":"fatal","error":"listen tcp :1323: bind: address already in use","time":"2023-09-04T21:36:25+02:00","message":"Failed to start the server"}
60+{"level":"info","time":"2023-09-04T21:36:25+02:00","message":"Server is listening on port 1323"}
61+{"level":"fatal","error":"listen tcp :1323: bind: address already in use","time":"2023-09-04T21:36:25+02:00","message":"Failed to start the server"}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close