http

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadJSON

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

ReadJSON reads the json body from the request and decodes it to v The origin of this function is from Alex Edwards

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, data any) error

WriteJSON writes the data to the ResponseWriter

Types

type Response

type Response struct {

	// Status
	Status string `json:"status"`

	// Message is for messages to the api consumer
	Message string `json:"message,omitempty"`

	// Data should used to wrap data which requested the api consumer
	Data W `json:"data,omitempty"`

	// Error is for a specific error message
	Error string `json:"error,omitempty"`

	// Errors is for more specific error message due a specific field
	Errors map[string]string `json:"errors,omitempty"`
}

type W

type W map[string]any

W is to wrap JSON-Data for the response e.g. `"resources": ["123", "234"]`

Jump to

Keyboard shortcuts

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