http

package
v0.0.0-...-cddfa53 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package http handles HTTP requests.

Index

Constants

This section is empty.

Variables

View Source
var ErrMalformedAuthHeader = errors.New("malformed authorization header")

ErrMalformedAuthHeader returned when authorization header is not formatted properly.

Functions

func ErrorInvalidQuery

func ErrorInvalidQuery(w http.ResponseWriter, r *http.Request)

ErrorInvalidQuery uese Error to reports invalid url quries.

func Errorf

func Errorf(w http.ResponseWriter, r *http.Request, code int, format string, a ...any)

Errorf prints errors to users as json and log server errors to stdout.

func FromJSON

func FromJSON(w http.ResponseWriter, r *http.Request, v any) error

FromJSON decodes to giving struct.

caller must pass v as pointer.

func New

func New(pg postgres.Postgres) *server

New returns a new instance of Server.

func ParseIntQuery

func ParseIntQuery(r *http.Request, v string) (int, error)

ParseIntQuery parses integer url parameter, returns nothing when parameter is not provided.

func ToJSON

func ToJSON(w http.ResponseWriter, v any, code int) error

ToJSON encodes to giving strcut.

Types

type WrapError

type WrapError struct {
	Error errorTemplate `json:"error"`
}

WrapError wraps error for user representation.

Jump to

Keyboard shortcuts

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