http

package
v0.0.0-...-4a05471 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2024 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Overview

Package http provides the server and API implementation for the webclient. The webclient's static files are also served.

Index

Constants

View Source
const (
	TagGenericError      = "GENERIC_ERROR"
	TagConnectionRefused = "CONNECTION_REFUSED"
	TagConnectionTimeout = "CONNECTION_TIMEOUT"
	TagResourceNotFound  = "NOT_FOUND"
	TagValidationError   = "VALIDATION_ERROR"
)

Error tags

View Source
const (
	CodeGeneric           = 42
	CodeConnectionRefused = 100
	CodeConnectionTimeout = 101
	CodeValidationError   = 400
	CodeResourceNotFound  = 404
)

Error codes

View Source
const (
	StatusError            = http.StatusInternalServerError
	StatusResourceNotFound = http.StatusNotFound
	StatusValidationError  = http.StatusBadRequest
	TimeoutError           = http.StatusGatewayTimeout
)

Error status codes

Variables

View Source
var (
	// ErrQueryTooShort will be returned when the query
	// is too short.
	ErrQueryTooShort = &ErrValidationFailed{
		"q", "the query is too short",
	}

	// ErrQueryIncomplete will be returned when the
	// prefix query lacks a : or .
	ErrQueryIncomplete = &ErrValidationFailed{
		"q", "a prefix query must contain at least a '.' or ':'",
	}
)
View Source
var (
	ErrSourceNotFound = &ErrResourceNotFoundError{}
)

Variables

Functions

func DurationMs

func DurationMs(d time.Duration) float64

DurationMs converts time.Duration to milliseconds

Types

type AppStatus

type AppStatus struct {
	Version   string                   `json:"version"`
	Routes    *api.RoutesStoreStats    `json:"routes"`
	Neighbors *api.NeighborsStoreStats `json:"neighbors"`
	Postgres  *postgres.Status         `json:"postgres"`
}

AppStatus contains application status information

func CollectAppStatus

func CollectAppStatus(
	ctx context.Context,
	pool *pgxpool.Pool,
	routesStore *store.RoutesStore,
	neighborsStore *store.NeighborsStore,
) (*AppStatus, error)

CollectAppStatus initializes the application status with stats gathered from the various application modules.

type ErrResourceNotFoundError

type ErrResourceNotFoundError struct{}

ErrResourceNotFoundError is a 404 error

func (*ErrResourceNotFoundError) Error

func (err *ErrResourceNotFoundError) Error() string

Error implements the error interface and returns the error message

type ErrTimeout

type ErrTimeout string

ErrTimeout will be sent if the request took too long

func (ErrTimeout) Error

func (err ErrTimeout) Error() string

Implement Error interface

type ErrValidationFailed

type ErrValidationFailed struct {
	Param  string `json:"param"`
	Reason string `json:"reason"`
}

ErrValidationFailed indicates that a parameter validation failed and the response should be a BadRequest.

func NewErrAmbigousParam

func NewErrAmbigousParam(key string) *ErrValidationFailed

NewErrAmbigousParam returns an ErrValidationFailed, indicating that the parameter was ambigous.

func NewErrEmptyParam

func NewErrEmptyParam(key string) *ErrValidationFailed

NewErrEmptyParam return an ErrValidationFailed if the provided parameter value is empty.

func NewErrMissingParam

func NewErrMissingParam(key string) *ErrValidationFailed

NewErrMissingParam returns a new error idicating a missing query parameter.

func (*ErrValidationFailed) Error

func (err *ErrValidationFailed) Error() string

Error implements the error interface

type QueryString

type QueryString string

QueryString wraps the q parameter from the query. Extract the value and additional filters from the string

func (QueryString) ExtractFilters

func (q QueryString) ExtractFilters() (string, []string)

ExtractFilters separates query and filters from string.

type Server

type Server struct {
	*http.Server
	// contains filtered or unexported fields
}

Server provides the HTTP server for the API and the assets.

func NewServer

func NewServer(
	cfg *config.Config,
	pool *pgxpool.Pool,
	routesStore *store.RoutesStore,
	neighborsStore *store.NeighborsStore,
) *Server

NewServer creates a new server

func (*Server) Start

func (s *Server) Start(ctx context.Context)

Start starts a HTTP server and begins to listen on the configured port.

type Theme

type Theme struct {
	Config config.ThemeConfig
}

Theme is a client customization through additional HTML, CSS and JS content.

func NewTheme

func NewTheme(config config.ThemeConfig) *Theme

NewTheme creates a theme from a config

func (*Theme) Handler

func (t *Theme) Handler() http.Handler

Handler is the theme HTTP handler

func (*Theme) HashInclude

func (t *Theme) HashInclude(include string) string

HashInclude calculates a hashvalue for an include file, to help with cache invalidation, when the file changes.

We are using the timestamp of the last access as Unix() encoded as hex

func (*Theme) PrepareClientHTML

func (t *Theme) PrepareClientHTML(html string) string

PrepareClientHTML prepares the document and fills placeholders with scripts and stylesheet.

func (*Theme) RegisterThemeAssets

func (t *Theme) RegisterThemeAssets(router *httprouter.Router) error

RegisterThemeAssets registers the theme at path

func (*Theme) ScriptIncludes

func (t *Theme) ScriptIncludes() string

ScriptIncludes makes include statement for scripts

func (*Theme) Scripts

func (t *Theme) Scripts() []string

Scripts retrieve a list of includeable javascipts

func (*Theme) StylesheetIncludes

func (t *Theme) StylesheetIncludes() string

StylesheetIncludes make include statements for stylesheet

func (*Theme) Stylesheets

func (t *Theme) Stylesheets() []string

Stylesheets retrieve a list of includeable stylesheets, with their md5sum as hash

Jump to

Keyboard shortcuts

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