From cecbeb78fe3d7ae0fd65b648764c0e98327d252c Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 10 Nov 2024 10:28:04 -0500 Subject: [PATCH] Rename ctx keys --- pkg/database/database.go | 8 ++++---- pkg/server/routes.go | 4 ++-- pkg/talkgroups/cache.go | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pkg/database/database.go b/pkg/database/database.go index f37b135..9f1c69b 100644 --- a/pkg/database/database.go +++ b/pkg/database/database.go @@ -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 diff --git a/pkg/server/routes.go b/pkg/server/routes.go index 9b66b88..aa3a8a1 100644 --- a/pkg/server/routes.go +++ b/pkg/server/routes.go @@ -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() diff --git a/pkg/talkgroups/cache.go b/pkg/talkgroups/cache.go index 7ada361..16b8ac6 100644 --- a/pkg/talkgroups/cache.go +++ b/pkg/talkgroups/cache.go @@ -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() }