refactor: follow the google go style guide
Document every package and exported identifier, return the log level from NewLogger instead of keeping it in a package variable, and stop tests from mutating the argon2 parameters. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
1 parent
048e114fd9
commit
d20225982a
21 files changed
+147
-36
No files matched your search
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Names shared with the browser side.
|
||||
const (
|
||||
CookieName = "__Host-session"
|
||||
CSRFHeader = "X-CSRF-Token"
|
||||
@@ -15,6 +16,8 @@ const (
|
||||
ctxKey = "auth.session"
|
||||
)
|
||||
|
||||
// SetCookie sends the session cookie. The __Host- prefix makes browsers
|
||||
// reject it unless it is Secure, host-only and scoped to /.
|
||||
func SetCookie(c *gin.Context, sess *Session, maxAge int) {
|
||||
http.SetCookie(c.Writer, &http.Cookie{
|
||||
Name: CookieName,
|
||||
@@ -27,6 +30,7 @@ func SetCookie(c *gin.Context, sess *Session, maxAge int) {
|
||||
})
|
||||
}
|
||||
|
||||
// ClearCookie removes the session cookie.
|
||||
func ClearCookie(c *gin.Context) {
|
||||
http.SetCookie(c.Writer, &http.Cookie{Name: CookieName, Value: "", Path: "/", MaxAge: -1, Secure: true, HttpOnly: true, SameSite: http.SameSiteLaxMode})
|
||||
}
|
||||
@@ -54,6 +58,7 @@ func (s *Sessions) Load() gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// Require aborts with 401 unless Load attached a session.
|
||||
func Require() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if Current(c) == nil {
|
||||
@@ -104,6 +109,7 @@ func sameOrigin(r *http.Request) bool {
|
||||
return err == nil && u.Host == r.Host
|
||||
}
|
||||
|
||||
// Current returns the session attached by Load, or nil.
|
||||
func Current(c *gin.Context) *Session {
|
||||
v, ok := c.Get(ctxKey)
|
||||
if !ok {
|
||||
|
||||
Reference in new issue
Block a user