authorizer/server/utils/ginContext.go
2021-07-14 18:52:00 +05:30

24 lines
424 B
Go

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