Documentation
¶
Index ¶
- Variables
- type Config
- type Context
- type ContextKey
- type HTTPService
- type Handler
- type HandlerChain
- type Metrics
- type Middleware
- type Result
- type ResultOption
- type Results
- func (r *Results) Abort() Result
- func (r *Results) Accepted(options ...ResultOption) Result
- func (r *Results) BadRequest(options ...ResultOption) Result
- func (r *Results) Bytes(body []byte) Result
- func (r *Results) Error(statusCode int, options ...ResultOption) Result
- func (r *Results) JSON(body any) Result
- func (r *Results) NotFound(options ...ResultOption) Result
- func (r *Results) Ok(options ...ResultOption) Result
- func (r *Results) PlainText(body []byte) Result
- func (r *Results) Redirect(uri string) Result
- func (r *Results) Unauthorized(options ...ResultOption) Result
- type Route
- func (r *Route) HasDescription(description string) *Route
- func (r *Route) HasOperationID(operationID string) *Route
- func (r *Route) HasPathParameter(name string, description string) *Route
- func (r *Route) HasQueryParameter(name string, description string) *Route
- func (r *Route) HasRequestModel(model any) *Route
- func (r *Route) HasResponse(statusCode int) *Route
- func (r *Route) HasResponseModel(statusCode int, model any) *Route
- func (r *Route) HasSummary(summary string) *Route
- func (r *Route) HasTags(tags ...string) *Route
- func (r *Route) IsDeprecated() *Route
- type RouteOpenAPISpec
- type RouteOpenAPISpecRequest
- type RouteOpenAPISpecResponse
- type RouteParameterType
- type Router
- func (r *Router) GetHandlers() []Handler
- func (r *Router) GetMux() *http.ServeMux
- func (r *Router) GetPath() string
- func (r *Router) GetRoutes() []*Route
- func (r *Router) Group(path string) *Router
- func (r *Router) Route(pattern string, handlers ...Handler) *Route
- func (r *Router) Use(handlers ...Handler)
- type RouterParameter
- type RouterParameterValidator
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrFailedToLoadCertificate = errors.New("failed to load certificate") ErrFailedToGenerateSelfSignedCert = errors.New("failed to generate self-signed certificate") ErrFailedToCreateHTTPMetrics = errors.New("failed to create HTTP metrics") ErrHTTPServiceNetListenError = errors.New("HTTP service net listen error") )
View Source
var ( ErrFailedToBuildHTTPRequestsCounter = errors.New( "failed to build HTTP requests counter", ) ErrFailedToBuildHTTPRequestDurationHistogram = errors.New( "failed to build HTTP request duration histogram", ) )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Addr string `conf:"addr" default:":8080"`
CertString string `conf:"cert_string"`
KeyString string `conf:"key_string"`
ReadHeaderTimeout time.Duration `conf:"read_header_timeout" default:"5s"`
ReadTimeout time.Duration `conf:"read_timeout" default:"10s"`
WriteTimeout time.Duration `conf:"write_timeout" default:"10s"`
IdleTimeout time.Duration `conf:"idle_timeout" default:"120s"`
InitializationTimeout time.Duration `conf:"init_timeout" default:"25s"`
GracefulShutdownTimeout time.Duration `conf:"shutdown_timeout" default:"5s"`
SelfSigned bool `conf:"self_signed" default:"false"`
HealthCheckEnabled bool `conf:"health_check" default:"true"`
OpenAPIEnabled bool `conf:"openapi" default:"true"`
ProfilingEnabled bool `conf:"profiling" default:"false"`
}
type Context ¶
type Context struct {
Request *http.Request
ResponseWriter http.ResponseWriter
Results Results
// contains filtered or unexported fields
}
func (*Context) UpdateContext ¶
type ContextKey ¶
type ContextKey string
type HTTPService ¶ added in v0.7.0
type HTTPService struct {
InnerServer *http.Server
InnerRouter *Router
InnerMetrics *Metrics
Config *Config
// contains filtered or unexported fields
}
func NewHTTPService ¶ added in v0.7.0
func NewHTTPService( config *Config, router *Router, metricsProvider *metricsfx.MetricsProvider, logger *logfx.Logger, ) *HTTPService
func (*HTTPService) Router ¶ added in v0.7.0
func (hs *HTTPService) Router() *Router
func (*HTTPService) Server ¶ added in v0.7.0
func (hs *HTTPService) Server() *http.Server
type HandlerChain ¶
type HandlerChain []Handler
type Metrics ¶
type Metrics struct {
Provider *metricsfx.MetricsProvider
RequestsTotal *metricsfx.CounterMetric
RequestDuration *metricsfx.HistogramMetric
}
Metrics holds HTTP-specific metrics using the simplified MetricsBuilder approach.
func NewMetrics ¶
func NewMetrics(provider *metricsfx.MetricsProvider) *Metrics
NewMetrics creates HTTP metrics using the simplified MetricsBuilder.
type Middleware ¶
type Middleware func() Handler
type Result ¶
type Result struct {
InnerRedirectToURI string
results.Result
InnerBody []byte
InnerStatusCode int
}
func (Result) RedirectToURI ¶ added in v0.7.0
func (Result) StatusCode ¶
func (Result) WithStatusCode ¶
type ResultOption ¶ added in v0.6.30
type ResultOption func(*Result)
Result Options.
func WithBody ¶ added in v0.6.30
func WithBody(body []byte) ResultOption
func WithJSON ¶ added in v0.7.0
func WithJSON(body any) ResultOption
func WithPlainText ¶ added in v0.6.30
func WithPlainText(body string) ResultOption
type Results ¶
type Results struct{}
Results With Options.
func (*Results) Accepted ¶ added in v0.6.30
func (r *Results) Accepted(options ...ResultOption) Result
func (*Results) BadRequest ¶
func (r *Results) BadRequest(options ...ResultOption) Result
func (*Results) NotFound ¶
func (r *Results) NotFound(options ...ResultOption) Result
func (*Results) Ok ¶
func (r *Results) Ok(options ...ResultOption) Result
func (*Results) Unauthorized ¶
func (r *Results) Unauthorized(options ...ResultOption) Result
type Route ¶
type Route struct {
Pattern *uris.Pattern
Parameters []RouterParameter
Handlers []Handler
MuxHandlerFunc func(http.ResponseWriter, *http.Request)
Spec RouteOpenAPISpec
}
func (*Route) HasDescription ¶
func (*Route) HasOperationID ¶ added in v0.7.0
func (*Route) HasPathParameter ¶
func (*Route) HasQueryParameter ¶
func (*Route) HasRequestModel ¶
func (*Route) HasResponse ¶
func (*Route) HasSummary ¶
func (*Route) IsDeprecated ¶
type RouteOpenAPISpec ¶ added in v0.7.0
type RouteOpenAPISpec struct {
OperationID string
Summary string
Description string
Tags []string
Requests []RouteOpenAPISpecRequest
Responses []RouteOpenAPISpecResponse
Deprecated bool
}
type RouteOpenAPISpecRequest ¶ added in v0.7.0
type RouteOpenAPISpecRequest struct {
Model any
}
type RouteOpenAPISpecResponse ¶ added in v0.7.0
type RouteParameterType ¶ added in v0.6.17
type RouteParameterType int
const ( RouteParameterTypeHeader RouteParameterType = iota RouteParameterTypeQuery RouteParameterTypePath RouteParameterTypeBody )
func (RouteParameterType) String ¶ added in v0.7.0
func (i RouteParameterType) String() string
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
func (*Router) GetHandlers ¶
type RouterParameter ¶ added in v0.6.17
type RouterParameter struct {
Name string
Description string
Validators []RouterParameterValidator
Type RouteParameterType
IsRequired bool
}
type RouterParameterValidator ¶ added in v0.6.17
Source Files
¶
Click to show internal directories.
Click to hide internal directories.