http

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2025 License: Apache-2.0 Imports: 15 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// 404 - Not Found
	RouteNotFound   = newErrorBuilder(http.StatusNotFound, "Route not found")
	ServiceNotFound = newErrorBuilder(http.StatusNotFound, "Service not found")
	APINotFound     = newErrorBuilder(http.StatusNotFound, "API not found")

	// 400 - Bad Request
	BadRequest = newErrorBuilder(http.StatusBadRequest, "Bad request")

	// 401 - Unauthorized
	Unauthorized = newErrorBuilder(http.StatusUnauthorized, "Unauthorized")

	// 403 - Forbidden
	Forbidden = newErrorBuilder(http.StatusForbidden, "Forbidden")

	// 405 - Method Not Allowed
	MethodNotAllowed = newErrorBuilder(http.StatusMethodNotAllowed, "Method not allowed")

	// 406 - Not Acceptable
	NotAcceptable = newErrorBuilder(http.StatusNotAcceptable, "Not acceptable")

	// 429 - Rate Limited
	RateLimited = newErrorBuilder(http.StatusTooManyRequests, "Rate limited")

	// 500 - Internal Server Error
	InternalError      = newErrorBuilder(http.StatusInternalServerError, "Internal server error")
	ConfigurationError = newErrorBuilder(http.StatusInternalServerError, "Configuration error")

	// 502 - Bad Gateway
	BadGateway = newErrorBuilder(http.StatusBadGateway, "Bad gateway")

	// 503 - Service Unavailable
	ServiceUnavailable = newErrorBuilder(http.StatusServiceUnavailable, "Service unavailable")

	// 504 - Gateway Timeout
	GatewayTimeout = newErrorBuilder(http.StatusGatewayTimeout, "Gateway timeout")
)

Predefined error response builders

Functions

This section is empty.

Types

type ErrorBuilder added in v1.1.0

type ErrorBuilder struct {
	// contains filtered or unexported fields
}

ErrorBuilder builds error responses

func (*ErrorBuilder) GetStatus added in v1.1.0

func (eb *ErrorBuilder) GetStatus() int

func (*ErrorBuilder) New added in v1.1.0

func (eb *ErrorBuilder) New() *ErrorResponse

New creates a standard error response without details

func (*ErrorBuilder) WithError added in v1.1.0

func (eb *ErrorBuilder) WithError(err error) *ErrorResponse

type ErrorResponse added in v1.1.0

type ErrorResponse struct {
	Status  int    `json:"status"`  // HTTP status code
	Message string `json:"message"` // Standard error message
	Err     error  `json:"-"`       // Underlying error, not marshaled directly
}

ErrorResponse represents the unified error response structure

func (*ErrorResponse) Error added in v1.1.0

func (e *ErrorResponse) Error() string

Error implements the error interface

func (*ErrorResponse) ToJSON added in v1.1.0

func (e *ErrorResponse) ToJSON() []byte

type FilterChain added in v1.1.0

type FilterChain []FilterFunc

FilterChain filter chain

type FilterFunc added in v1.1.0

type FilterFunc func(c *HttpContext)

FilterFunc filter func, filter

type HttpContext

type HttpContext struct {
	//Deprecated: waiting to delete
	Index int8
	//Deprecated: waiting to delete
	Filters FilterChain
	Timeout time.Duration
	Ctx     context.Context
	Params  map[string]any

	// the response context will return.
	TargetResp any
	// client call response.
	SourceResp any

	HttpConnectionManager model.HttpConnectionManagerConfig
	Route                 *model.RouteAction
	Api                   *router.API

	Request *http.Request
	Writer  http.ResponseWriter
	// contains filtered or unexported fields
}

HttpContext http context

func (*HttpContext) API

func (hc *HttpContext) API(api router.API)

API sets the API to http context

func (*HttpContext) Abort deprecated added in v1.1.0

func (hc *HttpContext) Abort()

Deprecated: Abort filter chain break , filter after the current filter will not executed.

func (*HttpContext) AddHeader

func (hc *HttpContext) AddHeader(k, v string)

AddHeader add header

func (*HttpContext) AllHeaders

func (hc *HttpContext) AllHeaders() http.Header

AllHeaders get all headers

func (*HttpContext) AppendFilterFunc deprecated added in v1.1.0

func (hc *HttpContext) AppendFilterFunc(ff ...FilterFunc)

Deprecated: AppendFilterFunc append filter func.

func (*HttpContext) ClearMetrics added in v1.1.0

func (hc *HttpContext) ClearMetrics()

ClearMetrics clears all recorded metrics.

func (*HttpContext) GenerateHash added in v1.1.0

func (hc *HttpContext) GenerateHash() string

func (*HttpContext) GetAPI

func (hc *HttpContext) GetAPI() *router.API

GetAPI get api

func (*HttpContext) GetAllMetrics added in v1.1.0

func (hc *HttpContext) GetAllMetrics() []*MetricData

GetAllMetrics returns all recorded metrics.

func (*HttpContext) GetApplicationName

func (hc *HttpContext) GetApplicationName() string

GetApplicationName get application name

func (*HttpContext) GetClientIP

func (hc *HttpContext) GetClientIP() string

GetClientIP get client IP

func (*HttpContext) GetHeader

func (hc *HttpContext) GetHeader(k string) string

GetHeader get header

func (*HttpContext) GetLocalReplyBody added in v1.1.0

func (hc *HttpContext) GetLocalReplyBody() []byte

func (*HttpContext) GetMethod

func (hc *HttpContext) GetMethod() string

GetMethod get method, POST/GET ...

func (*HttpContext) GetRouteEntry added in v1.1.0

func (hc *HttpContext) GetRouteEntry() *model.RouteAction

GetRouteEntry get route

func (*HttpContext) GetStatusCode added in v1.1.0

func (hc *HttpContext) GetStatusCode() int

func (*HttpContext) GetUrl

func (hc *HttpContext) GetUrl() string

GetUrl get http request url

func (*HttpContext) LocalReply added in v1.1.0

func (hc *HttpContext) LocalReply() bool

func (*HttpContext) Next deprecated

func (hc *HttpContext) Next()

Deprecated: Next logic for lookup filter

func (*HttpContext) RecordMetric added in v1.1.0

func (hc *HttpContext) RecordMetric(name string, metricType string, value float64, labels map[string]string)

RecordMetric records a metric to the context.

func (*HttpContext) Reset

func (hc *HttpContext) Reset()

Reset reset http context

func (*HttpContext) RouteEntry added in v1.1.0

func (hc *HttpContext) RouteEntry(r *model.RouteAction)

RouteEntry set route

func (*HttpContext) SendLocalReply added in v1.1.0

func (hc *HttpContext) SendLocalReply(status int, body []byte)

SendLocalReply Means that the request was interrupted and UnaryResponse will be sent directly Even if it’s currently in to Decode stage

func (*HttpContext) SetUrl added in v1.1.0

func (hc *HttpContext) SetUrl(url string)

func (*HttpContext) StatusCode

func (hc *HttpContext) StatusCode(code int)

type MetricData added in v1.1.0

type MetricData struct {
	Name   string            // Metric name
	Type   string            // Metric type: "counter", "histogram", "gauge"
	Value  float64           // Metric value
	Labels map[string]string // Metric labels
}

MetricData represents a single metric data point.

Jump to

Keyboard shortcuts

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