common

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateHandler

func CreateHandler[Req, Res any](endpoint Endpoint[Req, Res],
	requestHandler RequestHandler[Req],
	responseHandler ResponseHandler[Res]) http.HandlerFunc

func EncodeToJSON

func EncodeToJSON(w http.ResponseWriter, obj interface{}, logger logging.Logger)

func ErrorFromMessage

func ErrorFromMessage(message APIErrorMessage) error

ErrorFromMessage will construct a new error that can hold a predefined error message.

func SendBadRequestResponse

func SendBadRequestResponse(w http.ResponseWriter, reqID string, logger logging.Logger, details string)

func SendConflictResponse

func SendConflictResponse(w http.ResponseWriter, reqID string, logger logging.Logger, details string)

func SendForbiddenResponse

func SendForbiddenResponse(w http.ResponseWriter, reqID string, logger logging.Logger, details string)

func SendInternalServerError

func SendInternalServerError(w http.ResponseWriter, reqID string, logger logging.Logger, details string)

func SendResponseWithStatusAndMessage

func SendResponseWithStatusAndMessage(w http.ResponseWriter, status int, reqID string, message APIErrorMessage, logger logging.Logger, details string)

func SendStatusNotFoundResponse

func SendStatusNotFoundResponse(w http.ResponseWriter, reqID string, logger logging.Logger, details string)

func SendUnauthorizedResponse

func SendUnauthorizedResponse(w http.ResponseWriter, reqID string, logger logging.Logger, details string)

Types

type APIError

type APIError struct {
	RequestID string          `json:"requestid"`
	Message   APIErrorMessage `json:"message"`
	Timestamp int64           `json:"timestamp"`
	Details   url.Values      `json:"details"`
}

APIError is the generic return type for any Failure during endpoint operations

func NewAPIError

func NewAPIError(reqID string, message APIErrorMessage, details url.Values) *APIError

NewAPIError creates a new instance of the `APIError` which will be returned to the client if an operation fails

type APIErrorMessage

type APIErrorMessage string

APIErrorMessage type holds predefined error message constructs for the clients

const (
	// TransactionParseErrorMessage indicates a json body parse error
	TransactionParseErrorMessage APIErrorMessage = "transaction.parse.error"
	// field data failed to validate, see details field for more information
	TransactionDataInvalidMessage APIErrorMessage = "transaction.data.invalid"
	// duplicate referenceId
	TransactionDataDuplicateMessage APIErrorMessage = "transaction.data.duplicate"
	// database error
	TransactionWriteErrorMessage APIErrorMessage = "transaction.write.error"
	// database error
	TransactionReadErrorMessage APIErrorMessage = "transaction.read.error"
	// adapter failure while creating payment link
	TransactionPaylingErrorMessage APIErrorMessage = "transaction.paylink.error"
	// no such transaction in the database
	TransactionIDNotFoundMessage APIErrorMessage = "transaction.id.notfound"
	// syntactically invalid transaction id, must be positive integer
	TransactionIDInvalidMessage APIErrorMessage = "transaction.id.invalid"
	// deletion is not possible, e.g. because the grace period has expired for a valid payment
	TransactionCannotDeleteMessage APIErrorMessage = "transaction.cannot.delete"
	// token missing completely or invalid or expired
	AuthUnauthorizedMessage APIErrorMessage = "auth.unauthorized"
	// permissions missing
	AuthForbiddenMessage APIErrorMessage = "auth.forbidden"
	// Request could not be parsed properly
	RequestParseErrorMessage APIErrorMessage = "request.parse.failed"
	// Request created a conflict
	RequestConflictMessage APIErrorMessage = "request.conflict"
	// Internal error
	InternalErrorMessage APIErrorMessage = "http.error.internal"
	// Unknown error
	UnknownErrorMessage APIErrorMessage = "http.error.unkonwn"
)

type AllClaims

type AllClaims struct {
	jwt.RegisteredClaims
	CustomClaims
}

type CtxKeyAPIKey

type CtxKeyAPIKey struct{}

type CtxKeyAccessToken

type CtxKeyAccessToken struct{}

type CtxKeyAdminHeader

type CtxKeyAdminHeader struct{}

TODO Remove after legacy system was replaced with 2FA See reference https://github.com/eurofurence/reg-payment-service/issues/57

type CtxKeyClaims

type CtxKeyClaims struct{}

type CtxKeyIdToken

type CtxKeyIdToken struct{}

type CustomClaims

type CustomClaims struct {
	EMail         string   `json:"email"`
	EMailVerified bool     `json:"email_verified"`
	Groups        []string `json:"groups,omitempty"`
	Name          string   `json:"name"`
}

type Endpoint

type Endpoint[Req, Res any] func(ctx context.Context, request *Req, logger logging.Logger) (*Res, error)

type RequestHandler

type RequestHandler[Req any] func(r *http.Request) (*Req, error)

type ResponseHandler

type ResponseHandler[Res any] func(ctx context.Context, res *Res, w http.ResponseWriter) error

Jump to

Keyboard shortcuts

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