load fetches a session by ID from the database and decodes its content into session.Values.
(ctx context.Context, session *sessions.Session)
| 330 | // load fetches a session by ID from the database and decodes its content |
| 331 | // into session.Values. |
| 332 | func (store *UserSessionStore) load(ctx context.Context, session *sessions.Session) error { |
| 333 | sessionId, err := uuid.Parse(session.ID) |
| 334 | if err != nil { |
| 335 | return fmt.Errorf("invalid session ID: %w", err) |
| 336 | } |
| 337 | |
| 338 | res, err := store.repo.GetById(ctx, sessionId) |
| 339 | if err != nil { |
| 340 | return err |
| 341 | } |
| 342 | |
| 343 | data := sessionDataJSON{} |
| 344 | |
| 345 | if len(res.Data) > 0 { |
| 346 | err = json.Unmarshal(res.Data, &data) |
| 347 | |
| 348 | if err != nil { |
| 349 | return err |
| 350 | } |
| 351 | } |
| 352 | |
| 353 | return securecookie.DecodeMulti(session.Name(), string(data.Data), &session.Values, store.codecs...) |
| 354 | } |
| 355 | |
| 356 | // MaxLength restricts the maximum length of new sessions to l. |
| 357 | // If l is 0 there is no limit to the size of a session, use with caution. |