Skip to content

Commit

Permalink
refactor: switch to structured logging with log/slog and update err…
Browse files Browse the repository at this point in the history
…or 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>
  • Loading branch information
appleboy committed Dec 29, 2024
1 parent 14e12ca commit f361a4d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions bearer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rule:
skip-rule: [go_gorilla_cookie_missing_http_only, go_gorilla_insecure_cookie]
9 changes: 6 additions & 3 deletions sessions.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package sessions

import (
"log"
"log/slog"
"net/http"

"github.com/gin-gonic/gin"
Expand All @@ -11,7 +11,7 @@ import (

const (
DefaultKey = "github.com/gin-contrib/sessions"
errorFormat = "[sessions] ERROR! %s\n"
errorFormat = "[sessions] ERROR!"
)

type Store interface {
Expand Down Expand Up @@ -131,7 +131,10 @@ func (s *session) Session() *sessions.Session {
var err error
s.session, err = s.store.Get(s.request, s.name)
if err != nil {
log.Printf(errorFormat, err)
slog.Error(errorFormat,
"err", err,
)
return nil
}
}
return s.session
Expand Down

0 comments on commit f361a4d

Please sign in to comment.