web

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context interface {
	// JSON sends a JSON response with the specified status code.
	JSON(statusCode int, obj interface{})
	// String sends a formatted string response with the specified status code.
	String(statusCode int, format string, values ...interface{})
	// Param retrieves a route parameter by name.
	Param(key string) string
	// Query retrieves a query parameter by name.
	Query(key string) string
	// BindJSON parses the request body as JSON into the given object.
	BindJSON(obj interface{}) error
	// Next executes the next handler in the middleware chain.
	Next()
	// Request returns the underlying HTTP request.
	Request() *http.Request
	// ClientIP returns the client's IP address.
	ClientIP() string
	// SetHeader sets a header in the response.
	SetHeader(key, value string)
}

Context abstracts the HTTP context used by the framework.

func NewGinContext

func NewGinContext(ctx *gin.Context) Context

NewGinContext wraps Gin's context

type HandlerFunc

type HandlerFunc func(ctx Context)

HandlerFunc defines a generic HTTP handler function type.

type Option

type Option func(*Options)

func WithAddress

func WithAddress(address string) Option

WithAddress sets the address for the server

func WithMiddleware

func WithMiddleware(middleware ...HandlerFunc) Option

WithMiddleware adds middleware to the server

func WithMode

func WithMode(mode string) Option

WithMode sets the mode for the server

func WithShutdownTimeout

func WithShutdownTimeout(timeout time.Duration) Option

WithShutdownTimeout sets the shutdown timeout for the server

type Options

type Options struct {
	Address         string
	Mode            string
	ShutdownTimeout time.Duration
	Middleware      []HandlerFunc
	Logger          gin.HandlerFunc // Custom logger middleware
}

Options contains configurable settings for the Gin web server

type Routable added in v0.9.0

type Routable interface {
	RegisterRoutes(router RouterGroup)
}

Routable is an optional interface that modules can implement to register HTTP routes.

type Router added in v0.9.0

type Router interface {
	GET(route string, handler HandlerFunc)
	POST(route string, handler HandlerFunc)
	PUT(route string, handler HandlerFunc)
	PATCH(route string, handler HandlerFunc)
	DELETE(route string, handler HandlerFunc)
	OPTIONS(route string, handler HandlerFunc)
	HEAD(route string, handler HandlerFunc)
}

Router defines the core HTTP routing interface.

type RouterGroup

type RouterGroup interface {
	Router
	// Group creates a new RouterGroup with the given prefix.
	Group(prefix string) RouterGroup
}

RouterGroup abstracts route grouping; it embeds Router.

type WebServer added in v0.9.0

type WebServer interface {
	RouterGroup
	// Use registers middleware handlers.
	Use(middleware ...HandlerFunc)
	// Start launches the web server.
	Start() error
	// Stop stops the web server.
	Stop() error
}

Server defines the abstraction for the web server.

func NewGinEngine added in v0.9.0

func NewGinEngine(opts ...Option) WebServer

NewGinEngine creates a new Gin-based engine with the provided options.

Jump to

Keyboard shortcuts

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