allow register mock

This commit is contained in:
Ming Deng
2021-04-14 23:13:11 +08:00
parent 641a791265
commit 452dae86be
5 changed files with 6 additions and 8 deletions

View File

@@ -54,7 +54,7 @@ func (c *TestController) HelloSession() {
c.Ctx.WriteString("error")
return
}
c.SetSession("name", "Tom")
_ = c.SetSession("name", "Tom")
c.Ctx.WriteString("set")
}

View File

@@ -77,6 +77,7 @@ func (s *SessionProvider) SessionAll(ctx context.Context) int {
// SessionGC do nothing
func (s *SessionProvider) SessionGC(ctx context.Context) {
// we do anything since we don't need to mock GC
}
@@ -105,6 +106,7 @@ func (s *SessionStore) SessionID(ctx context.Context) string {
// SessionRelease do nothing
func (s *SessionStore) SessionRelease(ctx context.Context, w http.ResponseWriter) {
// Support in the future if necessary, now I think we don't need to implement this
}
func (s *SessionStore) Flush(ctx context.Context) error {

View File

@@ -70,15 +70,11 @@ var provides = make(map[string]Provider)
var SLogger = NewSessionLog(os.Stderr)
// Register makes a session provide available by the provided name.
// If Register is called twice with the same name or if driver is nil,
// it panics.
// If provider is nil, it panic
func Register(name string, provide Provider) {
if provide == nil {
panic("session: Register provide is nil")
}
if _, dup := provides[name]; dup {
panic("session: Register called twice for provider " + name)
}
provides[name] = provide
}