Refactor settings handling to support context-based reloading and add utility functions for context management
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2026-02-19 11:06:05 +11:00
parent f2d6b3158b
commit 504621f80d
5 changed files with 50 additions and 4 deletions

View File

@@ -0,0 +1,28 @@
package settings
import "context"
type reloadedContextKey struct{}
// MarkReloadedInContext marks that a given Settings instance has been refreshed in this context flow.
func MarkReloadedInContext(ctx context.Context, cfg *Settings) context.Context {
if ctx == nil {
ctx = context.Background()
}
if cfg == nil {
return ctx
}
return context.WithValue(ctx, reloadedContextKey{}, cfg)
}
// IsReloadedInContext reports whether this context flow already refreshed the provided Settings.
func IsReloadedInContext(ctx context.Context, cfg *Settings) bool {
if ctx == nil || cfg == nil {
return false
}
marked, ok := ctx.Value(reloadedContextKey{}).(*Settings)
if !ok || marked == nil {
return false
}
return marked == cfg
}