From 09b6234bb4adee22e0bec8706c2b838b6873fb5f Mon Sep 17 00:00:00 2001 From: indaco Date: Mon, 6 May 2024 12:07:55 +0200 Subject: [PATCH] fix(context.go): properly handle get data from context when echo.Context --- context.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/context.go b/context.go index 7dbc333..e08c7df 100644 --- a/context.go +++ b/context.go @@ -7,11 +7,20 @@ import ( // Define the context key type. type contextKey string +func (k contextKey) String() string { + return string(k) +} + // GetConfigMapFromContext retrieves the tab configuration from the context. func GetConfigMapFromContext(ctx context.Context) *ConfigMap { + // go-staticcheck(SA1029):not use built-in type string as key for value, define your own type. if opts, ok := ctx.Value(ConfigContextKey).(*ConfigMap); ok { return opts } + // When echo.Context, to get data the key must be a string. + if opts, ok := ctx.Value(ConfigContextKey.String()).(*ConfigMap); ok { + return opts + } return &ConfigMap{ Data: make(map[string]Config), }