Documentation
¶
Overview ¶
Package httpserver implements some utilities for HTTP servers.
Index ¶
- func ListenAndServe(ctx *appcontext.Context, port uint16, h http.Handler) error
- func NewRouter(ctx *appcontext.Context, opts RouterOpts) *gin.Engine
- func RespondError(ctx *appcontext.Context, c *gin.Context, statusCode int, err error)
- func RespondErrorInternalServer(ctx *appcontext.Context, c *gin.Context, err error)
- func RespondErrorNotFound(ctx *appcontext.Context, c *gin.Context, err error)
- func RespondOK(_ *appcontext.Context, c *gin.Context, resp interface{})
- type ErrorResponse
- type MetricResponse
- type PageCheckMetricsResponse
- type PageMetricsResponse
- type PageResponse
- type RouterOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ListenAndServe ¶
ListenAndServe listens on :port for requests and serves them using the HTTP handler. It honors context and hence exits gracefully when the context is canceled.
func NewRouter ¶
func NewRouter(ctx *appcontext.Context, opts RouterOpts) *gin.Engine
NewRouter returns an instance of the gin router with the required configurations and setup for the application.
func RespondError ¶
RespondError writes an error response to the request.
func RespondErrorInternalServer ¶
func RespondErrorInternalServer(ctx *appcontext.Context, c *gin.Context, err error)
RespondErrorInternalServer is same as calling RespondError(ctx, c, 500, err).
func RespondErrorNotFound ¶
func RespondErrorNotFound(ctx *appcontext.Context, c *gin.Context, err error)
RespondErrorNotFound is same as calling RespondError(ctx, c, 404, error).
Types ¶
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
}
ErrorResponse is the standard response for errors.
type MetricResponse ¶
type MetricResponse struct { Successful bool `json:"successful"` Timeout bool `json:"timeout"` StartTime time.Time `json:"start_time"` Duration time.Duration `json:"duration"` }
MetricResponse is the JSON response for returning metrics.
type PageCheckMetricsResponse ¶
type PageCheckMetricsResponse struct { Metrics []MetricResponse `json:"metrics"` Uptime int `json:"uptime"` Operational bool `json:"operational"` }
PageCheckMetricsResponse is the JSON response for all the metrics related to a particular check.
type PageMetricsResponse ¶
type PageMetricsResponse struct { ChecksDown int `json:"checks_down"` Checks map[string]PageCheckMetricsResponse `json:"checks"` }
PageMetricsResponse is the JSON response for returning all the metrics related information which is fetched once the page is loaded.
type PageResponse ¶
type PageResponse struct { Name string Checks map[string]string StaticURL string MetricsURL string LogoURL string FaviconURL string WebsiteURL string }
PageResponse is the data passed into the template.
type RouterOpts ¶
type RouterOpts struct { AllowedOrigins []string // use "*" to allow all origins. AllowedMethods []string // GET and POST are allowed by default. // contains filtered or unexported fields }
RouterOpts are the options used in creating a new router.