• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stackus / sessions / 11645237424

02 Nov 2024 07:23PM UTC coverage: 82.526%. Remained the same
11645237424

push

github

stackus
unexport registry

4 of 5 new or added lines in 1 file covered. (80.0%)

392 of 475 relevant lines covered (82.53%)

21.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.71
/registry.go
1
package sessions
2

3
import (
4
        "context"
5
        "net/http"
6

7
        "github.com/stackus/errors"
8
)
9

10
type registrySession interface {
11
        Save(w http.ResponseWriter, r *http.Request) error
12
}
13

14
type contextKey int
15

16
const sessionsKey contextKey = 10912
17

18
type registry struct {
19
        sessions map[string]registrySession
20
}
21

22
func getRegistry(r *http.Request) *registry {
39✔
23
        ctx := r.Context()
39✔
24

39✔
25
        if reg := ctx.Value(sessionsKey); reg != nil {
39✔
NEW
26
                return reg.(*registry)
×
27
        }
×
28

29
        reg := &registry{
39✔
30
                sessions: make(map[string]registrySession),
39✔
31
        }
39✔
32

39✔
33
        *r = *r.WithContext(context.WithValue(ctx, sessionsKey, reg))
39✔
34

39✔
35
        return reg
39✔
36
}
37

38
func (r *registry) get(name string) any {
39✔
39
        return r.sessions[name]
39✔
40
}
39✔
41

42
func (r *registry) set(name string, session registrySession) {
33✔
43
        r.sessions[name] = session
33✔
44
}
33✔
45

46
// Save saves all sessions in the registry for the provided request.
47
func Save(w http.ResponseWriter, r *http.Request) error {
×
48
        reg := getRegistry(r)
×
49

×
50
        var errs []error
×
51
        for name, session := range reg.sessions {
×
52
                if err := session.Save(w, r); err != nil {
×
53
                        errs = append(errs, errors.ErrInternalServerError.Wrapf(err, "registry: error while saving session: %q", name))
×
54
                }
×
55
        }
56
        return errors.Join(errs...)
×
57
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc