Documentation
¶
Index ¶
- Variables
- type ErrorBuilder
- type ErrorResponse
- type FilterChain
- type FilterFunc
- type HttpContext
- func (hc *HttpContext) API(api router.API)
- func (hc *HttpContext) Abort()deprecated
- func (hc *HttpContext) AddHeader(k, v string)
- func (hc *HttpContext) AllHeaders() http.Header
- func (hc *HttpContext) AppendFilterFunc(ff ...FilterFunc)deprecated
- func (hc *HttpContext) ClearMetrics()
- func (hc *HttpContext) GenerateHash() string
- func (hc *HttpContext) GetAPI() *router.API
- func (hc *HttpContext) GetAllMetrics() []*MetricData
- func (hc *HttpContext) GetApplicationName() string
- func (hc *HttpContext) GetClientIP() string
- func (hc *HttpContext) GetHeader(k string) string
- func (hc *HttpContext) GetLocalReplyBody() []byte
- func (hc *HttpContext) GetMethod() string
- func (hc *HttpContext) GetRouteEntry() *model.RouteAction
- func (hc *HttpContext) GetStatusCode() int
- func (hc *HttpContext) GetUrl() string
- func (hc *HttpContext) LocalReply() bool
- func (hc *HttpContext) Next()deprecated
- func (hc *HttpContext) RecordMetric(name string, metricType string, value float64, labels map[string]string)
- func (hc *HttpContext) Reset()
- func (hc *HttpContext) RouteEntry(r *model.RouteAction)
- func (hc *HttpContext) SendLocalReply(status int, body []byte)
- func (hc *HttpContext) SetUrl(url string)
- func (hc *HttpContext) StatusCode(code int)
- type MetricData
Constants ¶
This section is empty.
Variables ¶
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") 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") 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 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) 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) 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) 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) 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)