Documentation ¶
Index ¶
- Constants
- func Accepted(c *fiber.Ctx, s any) error
- func AllowFullOptionsWithCORS(app *fiber.App)
- func ApplyCursorPagination(findAll squirrel.SelectBuilder, decodedCursor Cursor, orderDirection string, ...) (squirrel.SelectBuilder, string)
- func BadRequest(c *fiber.Ctx, s any) error
- func Conflict(c *fiber.Ctx, code, title, message string) error
- func Created(c *fiber.Ctx, s any) error
- func File(filePath string) fiber.Handler
- func Forbidden(c *fiber.Ctx, code, title, message string) error
- func GetFileFromHeader(ctx *fiber.Ctx) (string, error)
- func GetPayloadFromContext(c *fiber.Ctx) any
- func GetRemoteAddress(r *http.Request) string
- func GetTokenHeader(c *fiber.Ctx) string
- func IPAddrFromRemoteAddr(s string) string
- func InternalServerError(c *fiber.Ctx, code, title, message string) error
- func JSONResponse(c *fiber.Ctx, status int, s any) error
- func JSONResponseError(c *fiber.Ctx, err pkg.ResponseError) error
- func NoContent(c *fiber.Ctx) error
- func NotFound(c *fiber.Ctx, code, title, message string) error
- func NotImplemented(c *fiber.Ctx, message string) error
- func NotImplementedEndpoint(c *fiber.Ctx) error
- func OK(c *fiber.Ctx, s any) error
- func PaginateRecords[T any](isFirstPage bool, hasPagination bool, pointsNext bool, items []T, limit int, ...) []T
- func ParseUUIDPathParameters(c *fiber.Ctx) error
- func PartialContent(c *fiber.Ctx, s any) error
- func Ping(c *fiber.Ctx) error
- func RangeNotSatisfiable(c *fiber.Ctx) error
- func ServeReverseProxy(target string, res http.ResponseWriter, req *http.Request)
- func Unauthorized(c *fiber.Ctx, code, title, message string) error
- func UnprocessableEntity(c *fiber.Ctx, code, title, message string) error
- func ValidateStruct(s any) error
- func Version(c *fiber.Ctx) error
- func Welcome(service string, description string) fiber.Handler
- func WithBasicAuth(f BasicAuthFunc, realm string) fiber.Handler
- func WithBody(s any, h DecodeHandlerFunc) fiber.Handler
- func WithCORS() fiber.Handler
- func WithDecode(c ConstructorFunc, h DecodeHandlerFunc) fiber.Handler
- func WithError(c *fiber.Ctx, err error) error
- func WithGrpcLogging(opts ...LogMiddlewareOption) grpc.UnaryServerInterceptor
- func WithHTTPLogging(opts ...LogMiddlewareOption) fiber.Handler
- type BasicAuthFunc
- type CasdoorTokenParser
- type ConstructorFunc
- type Cursor
- type CursorPagination
- type DecodeHandlerFunc
- type JWKProvider
- type JWTMiddleware
- func (jwtm *JWTMiddleware) ProtectGrpc() grpc.UnaryServerInterceptor
- func (jwtm *JWTMiddleware) ProtectHTTP() fiber.Handler
- func (jwtm *JWTMiddleware) WithPermissionGrpc() grpc.UnaryServerInterceptor
- func (jwtm *JWTMiddleware) WithPermissionHTTP(resource string) fiber.Handler
- func (jwtm *JWTMiddleware) WithScope(scopes []string) fiber.Handler
- type LogMiddlewareOption
- type OAuth2JWTToken
- type Pagination
- type PayloadContextValue
- type ProfileID
- type QueryHeader
- type RequestInfo
- type ResponseMetricsWrapper
- type TelemetryMiddleware
- func (tm *TelemetryMiddleware) EndTracingSpans(c *fiber.Ctx) error
- func (tm *TelemetryMiddleware) EndTracingSpansInterceptor() grpc.UnaryServerInterceptor
- func (tm *TelemetryMiddleware) WithTelemetry(tl *mopentelemetry.Telemetry) fiber.Handler
- func (tm *TelemetryMiddleware) WithTelemetryInterceptor(tl *mopentelemetry.Telemetry) grpc.UnaryServerInterceptor
- type TokenContextValue
- type TokenParser
Constants ¶
const (
HeaderMidazID = "Midaz-ID"
)
Variables ¶
This section is empty.
Functions ¶
func AllowFullOptionsWithCORS ¶
func AllowFullOptionsWithCORS(app *fiber.App)
AllowFullOptionsWithCORS set r.Use(WithCORS) and allow every request to use OPTION method.
func ApplyCursorPagination ¶ added in v1.31.0
func ApplyCursorPagination(findAll squirrel.SelectBuilder, decodedCursor Cursor, orderDirection string, limit int) (squirrel.SelectBuilder, string)
ApplyCursorPagination applies cursor-based pagination to a query.
func BadRequest ¶
BadRequest sends an HTTP 400 Bad Request response with a custom body.
func Forbidden ¶
Forbidden sends an HTTP 403 Forbidden response with a custom code, title and message.
func GetFileFromHeader ¶
GetFileFromHeader method that get file from header and give a string fom this dsl gold file
func GetPayloadFromContext ¶
func GetPayloadFromContext(c *fiber.Ctx) any
GetPayloadFromContext retrieves the decoded request payload from the Fiber context.
func GetRemoteAddress ¶
GetRemoteAddress returns IP address of the client making the request. It checks for X-Real-Ip or X-Forwarded-For headers which is used by Proxies.
func GetTokenHeader ¶
func GetTokenHeader(c *fiber.Ctx) string
GetTokenHeader func that get token from header
func IPAddrFromRemoteAddr ¶
IPAddrFromRemoteAddr removes port information from string.
func InternalServerError ¶
InternalServerError sends an HTTP 500 Internal Server Error response
func JSONResponse ¶
JSONResponse sends a custom status code and body as a JSON response.
func JSONResponseError ¶
func JSONResponseError(c *fiber.Ctx, err pkg.ResponseError) error
JSONResponseError sends a JSON formatted error response with a custom error struct.
func NoContent ¶
func NoContent(c *fiber.Ctx) error
NoContent sends an HTTP 204 No Content response without any body.
func NotFound ¶
NotFound sends an HTTP 404 Not Found response with a custom code, title and message.
func NotImplemented ¶
NotImplemented sends an HTTP 501 Not Implemented response with a custom message.
func NotImplementedEndpoint ¶
func NotImplementedEndpoint(c *fiber.Ctx) error
NotImplementedEndpoint returns HTTP 501 with not implemented message.
func PaginateRecords ¶ added in v1.31.0
func PaginateRecords[T any](isFirstPage bool, hasPagination bool, pointsNext bool, items []T, limit int, orderDirection string) []T
PaginateRecords paginates records based on the cursor.
func ParseUUIDPathParameters ¶
func ParseUUIDPathParameters(c *fiber.Ctx) error
ParseUUIDPathParameters globally, considering all path parameters are UUIDs
func PartialContent ¶
PartialContent sends an HTTP 206 Partial Content response with a custom body.
func RangeNotSatisfiable ¶
func RangeNotSatisfiable(c *fiber.Ctx) error
RangeNotSatisfiable sends an HTTP 416 Requested Range Not Satisfiable response.
func ServeReverseProxy ¶
func ServeReverseProxy(target string, res http.ResponseWriter, req *http.Request)
ServeReverseProxy serves a reverse proxy for a given url.
func Unauthorized ¶
Unauthorized sends an HTTP 401 Unauthorized response with a custom code, title and message.
func UnprocessableEntity ¶
UnprocessableEntity sends an HTTP 422 Unprocessable Entity response with a custom code, title and message.
func ValidateStruct ¶
ValidateStruct validates a struct against defined validation rules, using the validator package.
func WithBasicAuth ¶
func WithBasicAuth(f BasicAuthFunc, realm string) fiber.Handler
WithBasicAuth creates a basic authentication middleware.
func WithBody ¶
func WithBody(s any, h DecodeHandlerFunc) fiber.Handler
WithBody wraps a handler function, providing it with an instance of the specified struct.
func WithCORS ¶
func WithCORS() fiber.Handler
WithCORS is a middleware that enables CORS. Replace it with a real CORS middleware implementation.
func WithDecode ¶
func WithDecode(c ConstructorFunc, h DecodeHandlerFunc) fiber.Handler
WithDecode wraps a handler function, providing it with a struct instance created using the provided constructor function.
func WithGrpcLogging ¶
func WithGrpcLogging(opts ...LogMiddlewareOption) grpc.UnaryServerInterceptor
WithGrpcLogging is a gRPC unary interceptor to log access to gRPC server.
func WithHTTPLogging ¶
func WithHTTPLogging(opts ...LogMiddlewareOption) fiber.Handler
WithHTTPLogging is a middleware to log access to http server. It logs access log according to Apache Standard Logs which uses Common Log Format (CLF) Ref: https://httpd.apache.org/docs/trunk/logs.html#common
Types ¶
type BasicAuthFunc ¶
BasicAuthFunc represents a func which returns if a username and password was authenticated or not. It returns true if authenticated, and false when not authenticated.
func FixedBasicAuthFunc ¶
func FixedBasicAuthFunc(username, password string) BasicAuthFunc
FixedBasicAuthFunc is a fixed username and password to use as BasicAuthFunc.
type CasdoorTokenParser ¶
type CasdoorTokenParser struct{}
func (*CasdoorTokenParser) ParseToken ¶
func (p *CasdoorTokenParser) ParseToken(token *jwt.Token) (*OAuth2JWTToken, error)
type ConstructorFunc ¶
type ConstructorFunc func() any
ConstructorFunc representing a constructor of any type.
type Cursor ¶ added in v1.31.0
func CreateCursor ¶ added in v1.31.0
CreateCursor creates a cursor encode struct.
func DecodeCursor ¶ added in v1.31.0
DecodeCursor decodes a cursor string.
type CursorPagination ¶ added in v1.31.0
CursorPagination entity to store cursor pagination to return to client
func CalculateCursor ¶ added in v1.31.0
func CalculateCursor(isFirstPage, hasPagination, pointsNext bool, firstItemID, lastItemID string) (CursorPagination, error)
CalculateCursor calculates the cursor pagination.
type DecodeHandlerFunc ¶
DecodeHandlerFunc is a handler which works with withBody decorator. It receives a struct which was decoded by withBody decorator before. Ex: json -> withBody -> DecodeHandlerFunc.
func SetBodyInContext ¶
func SetBodyInContext(handler fiber.Handler) DecodeHandlerFunc
SetBodyInContext is a higher-order function that wraps a Fiber handler, injecting the decoded body into the request context.
type JWKProvider ¶
type JWKProvider struct { URI string CacheDuration time.Duration // contains filtered or unexported fields }
JWKProvider manages cryptographic public keys issued by an authorization server See https://tools.ietf.org/html/rfc7517 It's used to verify JSON Web Tokens which was signed using RS256 signing algorithm.
type JWTMiddleware ¶
type JWTMiddleware struct { JWK *JWKProvider // contains filtered or unexported fields }
JWTMiddleware represents a middleware which protects endpoint using JWT tokens.
func NewJWTMiddleware ¶
func NewJWTMiddleware(cc *mcasdoor.CasdoorConnection) *JWTMiddleware
NewJWTMiddleware create an instance of JWTMiddleware It uses JWK cache duration of 1 hour.
func (*JWTMiddleware) ProtectGrpc ¶
func (jwtm *JWTMiddleware) ProtectGrpc() grpc.UnaryServerInterceptor
ProtectGrpc protects any gRPC endpoint using JWT tokens.
func (*JWTMiddleware) ProtectHTTP ¶
func (jwtm *JWTMiddleware) ProtectHTTP() fiber.Handler
ProtectHTTP protects any endpoint using JWT tokens.
func (*JWTMiddleware) WithPermissionGrpc ¶
func (jwtm *JWTMiddleware) WithPermissionGrpc() grpc.UnaryServerInterceptor
WithPermissionGrpc verify if a requester has the required permission to access an endpoint.
func (*JWTMiddleware) WithPermissionHTTP ¶
func (jwtm *JWTMiddleware) WithPermissionHTTP(resource string) fiber.Handler
WithPermissionHTTP verify if a requester has the required permission to access an endpoint.
func (*JWTMiddleware) WithScope ¶
func (jwtm *JWTMiddleware) WithScope(scopes []string) fiber.Handler
WithScope verify if a requester has the required scope to access an endpoint.
type LogMiddlewareOption ¶
type LogMiddlewareOption func(l *logMiddleware)
LogMiddlewareOption represents the log middleware function as an implementation.
func WithCustomLogger ¶
func WithCustomLogger(logger mlog.Logger) LogMiddlewareOption
WithCustomLogger is a functional option for logMiddleware.
type OAuth2JWTToken ¶
type OAuth2JWTToken struct { Token *jwt.Token Claims jwt.MapClaims Groups []string Sub string Username *string Owner string Scope string ScopeSet map[string]bool }
OAuth2JWTToken represents a self-contained way for securely transmitting information between parties as a JSON object https://tools.ietf.org/html/rfc7519
func TokenFromContext ¶
func TokenFromContext(c *fiber.Ctx, parser TokenParser) (*OAuth2JWTToken, error)
type Pagination ¶ added in v1.31.0
type Pagination struct { Limit int Page int Cursor string SortOrder string StartDate time.Time EndDate time.Time }
Pagination entity from query parameter from get apis
type PayloadContextValue ¶
type PayloadContextValue string
PayloadContextValue is a wrapper type used to keep Context.Locals safe.
type QueryHeader ¶
type QueryHeader struct { Metadata *bson.M Limit int Page int Cursor string SortOrder string StartDate time.Time EndDate time.Time UseMetadata bool PortfolioID string ToAssetCodes []string }
QueryHeader entity from query parameter from get apis
func ValidateParameters ¶
func ValidateParameters(params map[string]string) (*QueryHeader, error)
ValidateParameters validate and return struct of default parameters
func (*QueryHeader) ToCursorPagination ¶ added in v1.31.0
func (qh *QueryHeader) ToCursorPagination() Pagination
func (*QueryHeader) ToOffsetPagination ¶ added in v1.31.0
func (qh *QueryHeader) ToOffsetPagination() Pagination
type RequestInfo ¶
type RequestInfo struct { Method string Username string URI string Referer string RemoteAddress string Status int Date time.Time Duration time.Duration UserAgent string MidazID string Protocol string Size int Body string }
RequestInfo is a struct design to store http access log data.
func NewRequestInfo ¶
func NewRequestInfo(c *fiber.Ctx) *RequestInfo
NewRequestInfo creates an instance of RequestInfo.
func (*RequestInfo) CLFString ¶
func (r *RequestInfo) CLFString() string
CLFString produces a log entry format similar to Common Log Format (CLF) Ref: https://httpd.apache.org/docs/trunk/logs.html#common
func (*RequestInfo) FinishRequestInfo ¶
func (r *RequestInfo) FinishRequestInfo(rw *ResponseMetricsWrapper)
FinishRequestInfo calculates the duration of RequestInfo automatically using time.Now() It also set StatusCode and Size of RequestInfo passed by ResponseMetricsWrapper.
func (*RequestInfo) String ¶
func (r *RequestInfo) String() string
String implements fmt.Stringer interface and produces a log entry using RequestInfo.CLFExtendedString.
type ResponseMetricsWrapper ¶
ResponseMetricsWrapper is a Wrapper responsible for collect the response data such as status code and size It implements built-in ResponseWriter interface.
type TelemetryMiddleware ¶
type TelemetryMiddleware struct {
*mopentelemetry.Telemetry
}
func NewTelemetryMiddleware ¶
func NewTelemetryMiddleware(tl *mopentelemetry.Telemetry) *TelemetryMiddleware
NewTelemetryMiddleware creates a new instance of TelemetryMiddleware.
func (*TelemetryMiddleware) EndTracingSpans ¶
func (tm *TelemetryMiddleware) EndTracingSpans(c *fiber.Ctx) error
EndTracingSpans is a middleware that ends the tracing spans.
func (*TelemetryMiddleware) EndTracingSpansInterceptor ¶
func (tm *TelemetryMiddleware) EndTracingSpansInterceptor() grpc.UnaryServerInterceptor
EndTracingSpansInterceptor is a gRPC interceptor that ends the tracing spans.
func (*TelemetryMiddleware) WithTelemetry ¶
func (tm *TelemetryMiddleware) WithTelemetry(tl *mopentelemetry.Telemetry) fiber.Handler
WithTelemetry is a middleware that adds tracing to the context.
func (*TelemetryMiddleware) WithTelemetryInterceptor ¶
func (tm *TelemetryMiddleware) WithTelemetryInterceptor(tl *mopentelemetry.Telemetry) grpc.UnaryServerInterceptor
WithTelemetryInterceptor is a gRPC interceptor that adds tracing to the context.
type TokenContextValue ¶
type TokenContextValue string
TokenContextValue is a wrapper type used to keep Context.Locals safe.
type TokenParser ¶
type TokenParser struct {
ParseToken func(*jwt.Token) (*OAuth2JWTToken, error)
}