Skip to content

Commit

Permalink
fix(context.go): properly handle get data from context when echo.Context
Browse files Browse the repository at this point in the history
  • Loading branch information
indaco committed May 6, 2024
1 parent fc8790e commit 09b6234
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down

0 comments on commit 09b6234

Please sign in to comment.