add README + golangci config + fix lint
This commit is contained in:
+13
-13
@@ -30,12 +30,12 @@ var APISecure = sync.OnceValue[bool](func() bool {
|
||||
})
|
||||
|
||||
var (
|
||||
ErrSessionIdCollision = errors.New("sessionId collision")
|
||||
ErrSessionIDCollision = errors.New("sessionId collision")
|
||||
ErrUnauthorized = errors.New("unauthorized")
|
||||
)
|
||||
|
||||
func generateSessionID() (string, error) {
|
||||
sessionID := make([]byte, 32)
|
||||
sessionID := make([]byte, 32) //nolint
|
||||
if _, err := rand.Read(sessionID); err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func generateSessionID() (string, error) {
|
||||
|
||||
type Session struct {
|
||||
l sync.RWMutex
|
||||
sessionId string
|
||||
sessionID string
|
||||
expirationTime time.Time
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func (s *Session) GenerateCookie() *http.Cookie {
|
||||
|
||||
return &http.Cookie{
|
||||
Name: "session_id",
|
||||
Value: s.sessionId,
|
||||
Value: s.sessionID,
|
||||
HttpOnly: true,
|
||||
Secure: APISecure(),
|
||||
Expires: s.expirationTime,
|
||||
@@ -97,13 +97,13 @@ func (s *SessionStore) purge() {
|
||||
}
|
||||
|
||||
for _, session := range toDelete {
|
||||
log.Debug().Str("sessionId", session.sessionId).Msg("purge expired session")
|
||||
delete(s.sessions, session.sessionId)
|
||||
log.Debug().Str("sessionId", session.sessionID).Msg("purge expired session")
|
||||
delete(s.sessions, session.sessionID)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *SessionStore) purgeWorker() {
|
||||
ticker := time.NewTicker(10 * time.Second)
|
||||
ticker := time.NewTicker(10 * time.Second) //nolint
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
@@ -127,7 +127,7 @@ func (s *SessionStore) Done() <-chan struct{} {
|
||||
}
|
||||
|
||||
func (s *SessionStore) NewSession() (*Session, error) {
|
||||
sessionId, err := generateSessionID()
|
||||
sessionID, err := generateSessionID()
|
||||
if err != nil {
|
||||
log.Err(err).Msg("unable to generate sessionId")
|
||||
return nil, err
|
||||
@@ -136,14 +136,14 @@ func (s *SessionStore) NewSession() (*Session, error) {
|
||||
s.l.Lock()
|
||||
defer s.l.Unlock()
|
||||
|
||||
if _, ok := s.sessions[sessionId]; ok {
|
||||
log.Error().Str("sessionId", sessionId).Msg("sessionId collision")
|
||||
return nil, ErrSessionIdCollision
|
||||
if _, ok := s.sessions[sessionID]; ok {
|
||||
log.Error().Str("sessionId", sessionID).Msg("sessionId collision")
|
||||
return nil, ErrSessionIDCollision
|
||||
}
|
||||
|
||||
now := time.Now().Add(APISessionExpirationDuration())
|
||||
session := Session{expirationTime: now, sessionId: sessionId}
|
||||
s.sessions[sessionId] = &session
|
||||
session := Session{expirationTime: now, sessionID: sessionID}
|
||||
s.sessions[sessionID] = &session
|
||||
|
||||
return &session, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user