web

package
v0.0.0-...-b69cb46 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

https://blog.questionable.services/article/http-handler-error-handling-revisited/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRouter

func NewRouter(e *env.Env) http.Handler

NewRouter creates a new router with all application routes.

func NewValidator

func NewValidator() *validator.Validate

Types

type Error

type Error interface {
	error
	Status() int
}

Error represents a handler error. It provides methods for a HTTP status code and embeds the built-in error interface.

type ErrorResponse

type ErrorResponse struct {
	Error  string   `json:"error"`
	Fields []string `json:"fields,omitempty"`
}

ErrorResponse is the client response struct for errors.

type StatusError

type StatusError struct {
	Err  error
	Code int
}

StatusError represents an error with an associated HTTP status code.

func (StatusError) Error

func (se StatusError) Error() string

Allows StatusError to satisfy the error interface.

func (StatusError) Status

func (se StatusError) Status() int

Returns our HTTP status code.

Directories

Path Synopsis
https://blog.questionable.services/article/guide-logging-middleware-go/
https://blog.questionable.services/article/guide-logging-middleware-go/

Jump to

Keyboard shortcuts

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