Documentation ¶
Overview ¶
Package http provides the server and API implementation for the webclient. The webclient's static files are also served.
Index ¶
- Constants
- Variables
- func DurationMs(d time.Duration) float64
- type AppStatus
- type ErrResourceNotFoundError
- type ErrTimeout
- type ErrValidationFailed
- type QueryString
- type Server
- type Theme
- func (t *Theme) Handler() http.Handler
- func (t *Theme) HashInclude(include string) string
- func (t *Theme) PrepareClientHTML(html string) string
- func (t *Theme) RegisterThemeAssets(router *httprouter.Router) error
- func (t *Theme) ScriptIncludes() string
- func (t *Theme) Scripts() []string
- func (t *Theme) StylesheetIncludes() string
- func (t *Theme) Stylesheets() []string
Constants ¶
const ( TagGenericError = "GENERIC_ERROR" TagConnectionRefused = "CONNECTION_REFUSED" TagConnectionTimeout = "CONNECTION_TIMEOUT" TagResourceNotFound = "NOT_FOUND" TagValidationError = "VALIDATION_ERROR" )
Error tags
const ( CodeGeneric = 42 CodeConnectionRefused = 100 CodeConnectionTimeout = 101 CodeValidationError = 400 CodeResourceNotFound = 404 )
Error codes
const ( StatusError = http.StatusInternalServerError StatusResourceNotFound = http.StatusNotFound StatusValidationError = http.StatusBadRequest TimeoutError = http.StatusGatewayTimeout )
Error status codes
Variables ¶
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 ':'", } )
var (
ErrSourceNotFound = &ErrResourceNotFoundError{}
)
Variables
Functions ¶
func DurationMs ¶
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 ErrValidationFailed ¶
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 ¶
Server provides the HTTP server for the API and the assets.
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) HashInclude ¶
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 ¶
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 ¶
ScriptIncludes makes include statement for scripts
func (*Theme) StylesheetIncludes ¶
StylesheetIncludes make include statements for stylesheet
func (*Theme) Stylesheets ¶
Stylesheets retrieve a list of includeable stylesheets, with their md5sum as hash