common

package
v0.0.0-...-341d7fa Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	InsecureSkipVerifyKey = "INSECURE_SKIP_VERIFY"
	HTTPPortKey           = "HTTP_PORT"
	GRPCPortKey           = "GRPC_PORT"
	DBHostKey             = "DB_HOST"
	DBPortKey             = "DB_PORT"
	DBUserKey             = "DB_USER"
	DBPassKey             = "DB_PASS"
	DBConnectionStringKey = "DB_CONNECTION_STRING"
	CertsEndpointKey      = "CERTS_ENDPOINT"

	JWTSecretKey             = "JWT_SECRET"
	IntrospectionEndpointKey = "INTROSPECTION_ENDPOINT"
	ClientIdKey              = "CLIENT_ID"
	ClientSecretKey          = "CLIENT_SECRET"
)
View Source
var (
	ErrCastRequest   = errors.New("cannot cast request")
	ErrCastResponse  = errors.New("cannot cast response")
	ErrParsingClaims = errors.New("error parsing claims")
	ErrUnauthorized  = errors.New("unauthorized")

	ErrAlreadyCreated = errors.New("resource already exists")
	ErrNotFound       = errors.New("resource not found error")
)

Functions

func DecodeJSONRequest

func DecodeJSONRequest[T any](_ context.Context, r *http.Request) (interface{}, error)

func DecodeNoBodyRequest

func DecodeNoBodyRequest(_ context.Context, r *http.Request) (interface{}, error)

func DecodePathParameters

func DecodePathParameters[T any](_ context.Context, r *http.Request) (interface{}, error)

func DefaultErr2Status

func DefaultErr2Status(err error) int

func EncodeResponse

func EncodeResponse(err2Status func(error) int) func(context.Context, http.ResponseWriter, interface{}) error

func Err2Str

func Err2Str(err error) string

func ErrorEncoder

func ErrorEncoder(err2Status func(error) int) func(_ context.Context, err error, w http.ResponseWriter)

func GRPCDecodeNoBody

func GRPCDecodeNoBody(_ context.Context, req interface{}) (interface{}, error)

func GRPCDecodeToObject

func GRPCDecodeToObject[T any](_ context.Context, request interface{}) (interface{}, error)

func GRPCLoggingServerOptions

func GRPCLoggingServerOptions(logger log.Logger) []grpctransport.ServerOption

func GetStandardClaimsFromContext

func GetStandardClaimsFromContext(ctx context.Context) (*jwt.RegisteredClaims, error)

func GetUserIdFromContext

func GetUserIdFromContext(ctx context.Context) (string, error)

func HTTPLoggingServerOptions

func HTTPLoggingServerOptions(logger log.Logger) []httptransport.ServerOption

func JWTKeyFactory

func JWTKeyFactory(viper viper.Viper) func(token *jwt.Token) (interface{}, error)

func NewParser

func NewParser(keyFunc jwt.Keyfunc, method jwt.SigningMethod, newClaims ClaimsFactory) endpoint.Middleware

NewParser creates a new JWT parsing middleware, specifying a jwt.Keyfunc interface, the signing method and the claims type to be used. NewParser adds the resulting claims to endpoint context or returns error on invalid token. Particularly useful for servers.

func RegisteredClaimsFactory

func RegisteredClaimsFactory() jwt.Claims

func SetConnectionStringConfig

func SetConnectionStringConfig(viper *viper.Viper)

Types

type ClaimsFactory

type ClaimsFactory func() jwt.Claims

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

func NewErrorResponse

func NewErrorResponse(err error) ErrorResponse

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址