Rename ctx keys
This commit is contained in:
parent
e97c9ced0e
commit
cecbeb78fe
3 changed files with 10 additions and 10 deletions
|
@ -56,13 +56,13 @@ func NewClient(ctx context.Context, conf config.DB) (*DB, error) {
|
|||
return db, nil
|
||||
}
|
||||
|
||||
type DBCtxKey string
|
||||
type dBCtxKey string
|
||||
|
||||
const DBCtxKeyValue DBCtxKey = "dbctx"
|
||||
const DBCtxKey dBCtxKey = "dbctx"
|
||||
|
||||
// FromCtx returns the database handle from the provided Context.
|
||||
func FromCtx(ctx context.Context) *DB {
|
||||
c, ok := ctx.Value(DBCtxKeyValue).(*DB)
|
||||
c, ok := ctx.Value(DBCtxKey).(*DB)
|
||||
if !ok {
|
||||
panic("no DB in context")
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ func FromCtx(ctx context.Context) *DB {
|
|||
|
||||
// CtxWithDB returns a Context with the provided database handle.
|
||||
func CtxWithDB(ctx context.Context, conn *DB) context.Context {
|
||||
return context.WithValue(ctx, DBCtxKeyValue, conn)
|
||||
return context.WithValue(ctx, DBCtxKey, conn)
|
||||
}
|
||||
|
||||
// IsNoRows is a convenience function that returns whether a returned error is a database
|
||||
|
|
|
@ -27,8 +27,8 @@ func (s *Server) setupRoutes() {
|
|||
}
|
||||
|
||||
r := s.r
|
||||
r.Use(middleware.WithValue(database.DBCtxKeyValue, s.db))
|
||||
r.Use(middleware.WithValue(talkgroups.StoreCtxKeyValue, s.tgs))
|
||||
r.Use(middleware.WithValue(database.DBCtxKey, s.db))
|
||||
r.Use(middleware.WithValue(talkgroups.StoreCtxKey, s.tgs))
|
||||
|
||||
s.installPprof()
|
||||
|
||||
|
|
|
@ -57,16 +57,16 @@ type Store interface {
|
|||
HUP(*config.Config)
|
||||
}
|
||||
|
||||
type CtxStoreKey string
|
||||
type storeCtxKey string
|
||||
|
||||
const StoreCtxKeyValue CtxStoreKey = "store"
|
||||
const StoreCtxKey storeCtxKey = "store"
|
||||
|
||||
func CtxWithStore(ctx context.Context, s Store) context.Context {
|
||||
return context.WithValue(ctx, StoreCtxKeyValue, s)
|
||||
return context.WithValue(ctx, StoreCtxKey, s)
|
||||
}
|
||||
|
||||
func StoreFrom(ctx context.Context) Store {
|
||||
s, ok := ctx.Value(StoreCtxKeyValue).(Store)
|
||||
s, ok := ctx.Value(StoreCtxKey).(Store)
|
||||
if !ok {
|
||||
return NewCache()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue