http_server

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: May 11, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

type App struct {
	RateLimiter *limiter.RateLimiter
	PathMap     map[string]string
	// contains filtered or unexported fields
}

func NewApp

func NewApp(
	addr int,
	RateLimiter *limiter.RateLimiter,
	PathMap map[string]string,
) *App

func (*App) Close

func (a *App) Close()

Close closes the service.

func (*App) Start

func (a *App) Start() error

Start starts the service.

type Handler

type Handler struct {
	RateLimiter *limiter.RateLimiter
	PathMap     map[string]string
}

func (*Handler) ConfigureMiddleware

func (h *Handler) ConfigureMiddleware(router *fiber.App)

func (*Handler) Reduce

func (h *Handler) Reduce(ctx context.Context, input *ReduceRequest) (*ReduceResponse, error)

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(api huma.API)

func (*Handler) Remove

func (h *Handler) Remove(ctx context.Context, input *RemoveRequest) (*RemoveResponse, error)

func (*Handler) Stats

func (h *Handler) Stats(ctx context.Context, input *StatsRequest) (*StatsResponse, error)

type ReduceRequest

type ReduceRequest struct {
	Key          string `path:"key" maxLength:"1024" example:"user:1" doc:"Key for the lock"`
	MaxTokens    int64  `path:"max_tokens" minimum:"1" example:"1000" doc:"Maximum number of tokens in the bucket"`
	RefillTime   int64  `path:"refill_time" minimum:"1" example:"60" doc:"Time in seconds to refill the bucket"`
	RefillAmount int64  `path:"refill_amount" minimum:"1" example:"100" doc:"Number of tokens to refill the bucket"`
	Tokens       int64  `path:"tokens" minimum:"1" example:"1" doc:"Number of tokens to reduce"`
}

type ReduceResponse

type ReduceResponse struct {
	Status int
	Body   ReduceResponseBody
}

type ReduceResponseBody

type ReduceResponseBody struct {
	Status string `json:"status" example:"OK" doc:"Status of the reduce operation"`
	Key    string `json:"key" example:"user:1" doc:"Key for the lock"`
	Tokens int64  `json:"tokens" example:"1" doc:"Number of tokens left in the bucket"`
}

type RemoveRequest

type RemoveRequest struct {
	Key          string `path:"key" maxLength:"1024" example:"user:1" doc:"Key for the lock"`
	MaxTokens    int64  `path:"max_tokens" minimum:"1" example:"1000" doc:"Maximum number of tokens in the bucket"`
	RefillTime   int64  `path:"refill_time" minimum:"1" example:"60" doc:"Time in seconds to refill the bucket"`
	RefillAmount int64  `path:"refill_amount" minimum:"1" example:"100" doc:"Number of tokens to refill the bucket"`
}

type RemoveResponse

type RemoveResponse struct {
	Status int
	Body   struct {
		Status string `json:"status" example:"OK" doc:"Status of the remove operation"`
	}
}

type StatsRequest

type StatsRequest struct {
}

type StatsResponse

type StatsResponse struct {
	Status int
	Body   StatsResponseBody
}

type StatsResponseBody

type StatsResponseBody struct {
	NumGoroutines int     `json:"num_goroutines" example:"1" doc:"Number of goroutines"`
	CPU           int64   `json:"cpu" example:"53373" doc:"CPU usage in nanoseconds"`
	MaxRSS        float64 `json:"max_rss" example:"15777792" doc:"Max RSS in bytes"`
	NumberOfKeys  int64   `json:"number_of_keys" example:"543" doc:"Number of keys in the rate limiter"`
}

Jump to

Keyboard shortcuts

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