Skip to content

Commit f361a4d

Browse files
committed
refactor: switch to structured logging with log/slog and update error handling
- Add `bearer.yml` file with rules to skip specific checks - Replace `log` package with `log/slog` in `sessions.go` - Simplify error format string in `sessions.go` - Update error logging in `sessions.go` to use `slog.Error` with structured logging and return `nil` on error Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent 14e12ca commit f361a4d

2 files changed

Lines changed: 8 additions & 3 deletions

File tree

bearer.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rule:
2+
skip-rule: [go_gorilla_cookie_missing_http_only, go_gorilla_insecure_cookie]

sessions.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package sessions
22

33
import (
4-
"log"
4+
"log/slog"
55
"net/http"
66

77
"github.com/gin-gonic/gin"
@@ -11,7 +11,7 @@ import (
1111

1212
const (
1313
DefaultKey = "github.com/gin-contrib/sessions"
14-
errorFormat = "[sessions] ERROR! %s\n"
14+
errorFormat = "[sessions] ERROR!"
1515
)
1616

1717
type Store interface {
@@ -131,7 +131,10 @@ func (s *session) Session() *sessions.Session {
131131
var err error
132132
s.session, err = s.store.Get(s.request, s.name)
133133
if err != nil {
134-
log.Printf(errorFormat, err)
134+
slog.Error(errorFormat,
135+
"err", err,
136+
)
137+
return nil
135138
}
136139
}
137140
return s.session

0 commit comments

Comments
 (0)