middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InternalServerError             string = "An unexpected error occurred while processing your request."
	RateLimitExceededError          string = "Slow down! Too many requests. Try again shortly. Thank you!"
	MissingXForwardedForHeaderError string = "X-Forwarded-For header is required for accurate processing."
)

Errors

Variables

This section is empty.

Functions

func AuthorizeUser

func AuthorizeUser(ctx context.Context, walletAddress string, authService services.AuthGrpcService) (*pb.AccessTokenPayload, error)

func CreateLimiterRedisStore

func CreateLimiterRedisStore(redisConnURL string) (limiter.Store, error)

func GrpcExtractMetadata

func GrpcExtractMetadata(ctx context.Context, req any, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)

func GrpcLogger

func GrpcLogger(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)

func GrpcRateLimiter

func GrpcRateLimiter(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)

func HTTPExtractMetadata

func HTTPExtractMetadata(handler http.Handler) http.Handler

func HTTPLogger

func HTTPLogger(handler http.Handler) http.Handler

func HTTPRateLimiter

func HTTPRateLimiter(handler http.Handler) http.Handler

func InitializeLimiters

func InitializeLimiters(store limiter.Store) error

Types

type ErrorResponse

type ErrorResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type ReqContextKey

type ReqContextKey string
const (
	ClientIP              ReqContextKey = "client_ip"
	ServiceAuthentication ReqContextKey = "service_authentication"
	AuthenticatedService  ReqContextKey = "authenticated_service"
)

type ResponseRecorder

type ResponseRecorder struct {
	http.ResponseWriter
	StatusCode int
	Body       []byte
}

func (*ResponseRecorder) Write

func (rec *ResponseRecorder) Write(body []byte) (int, error)

func (*ResponseRecorder) WriteHeader

func (rec *ResponseRecorder) WriteHeader(statusCode int)

Jump to

Keyboard shortcuts

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