authorizer/server/utils/gin_context.go
2022-07-29 19:49:50 +05:30

27 lines
515 B
Go

package utils
import (
"context"
"fmt"
"github.com/gin-gonic/gin"
)
// TODO re-name 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
}