httpserver

package
v0.1.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package httpserver implements some utilities for HTTP servers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListenAndServe

func ListenAndServe(ctx *appcontext.Context, port uint16, h http.Handler) error

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

func RespondError(ctx *appcontext.Context, c *gin.Context, statusCode int, err error)

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).

func RespondOK

func RespondOK(_ *appcontext.Context, c *gin.Context, resp interface{})

RespondOK writes an OK response to the request.

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.

Jump to

Keyboard shortcuts

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