authorizer/server/utils/gin_context.go

27 lines
515 B
Go
Raw Permalink Normal View History

package utils
import (
"context"
"fmt"
"github.com/gin-gonic/gin"
)
2022-01-17 06:02:13 +00:00
// TODO renamae GinContextKey -> GinContext
// GinContext to get gin context from context
func GinContextFromContext(ctx context.Context) (*gin.Context, error) {
ginContext := ctx.Value("GinContextKey")
if ginContext == nil {
err := fmt.Errorf("could not retrieve gin.Context")
return nil, err
}
gc, ok := ginContext.(*gin.Context)
if !ok {
err := fmt.Errorf("gin.Context has wrong type")
return nil, err
}
return gc, nil
}