httpapi

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read

func Read(rw http.ResponseWriter, r *http.Request, value interface{}) bool

Read decodes JSON from the HTTP request into the value provided. It uses go-validator to validate the incoming request body.

func WebsocketCloseSprintf

func WebsocketCloseSprintf(format string, vars ...any) string

WebsocketCloseSprintf formats a websocket close message and ensures it is truncated to the maximum allowed length.

func Write

func Write(rw http.ResponseWriter, status int, response Response)

Write outputs a standardized format to an HTTP response body.

Types

type Error

type Error struct {
	Field string `json:"field" validate:"required"`
	Code  string `json:"code" validate:"required"`
}

Error represents a scoped error to a user input.

type Response

type Response struct {
	Message string  `json:"message" validate:"required"`
	Errors  []Error `json:"errors,omitempty" validate:"required"`
}

Response represents a generic HTTP response.

Jump to

Keyboard shortcuts

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