json

package
v1.7.14 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeRequest

func DecodeRequest(r *http.Request, data any) (err error)

DecodeRequest decodes http request body.

func DecodeResponse added in v0.0.25

func DecodeResponse(res *http.Response, data any) (err error)

DecodeResponse decodes http response body.

func EncodeRequest added in v0.0.25

func EncodeRequest(req *http.Request, data any, contentTypes ...string) error

EncodeRequest encodes http request.

func EncodeResponse

func EncodeResponse(w http.ResponseWriter, data any, status int, contentTypes ...string) error

EncodeResponse encodes http response body.

func ErrorHandler

func ErrorHandler(w http.ResponseWriter, r *http.Request, msg string, code int, err error) error

ErrorHandler responds to an HTTP request to send RFC 7807 error.

func Handler

func Handler(
	w http.ResponseWriter, r *http.Request, data any, logic func() (any,
		error),
) (code int, err error)

Handler responds to an HTTP request to perform a logic function.

func Request added in v0.0.25

func Request(ctx context.Context, method, url string, payload, data any) error

Request sends http json request.

Types

type RFC7807Error

type RFC7807Error struct {
	Type     string `json:"type"`
	Title    string `json:"title"`
	Detail   any    `json:"detail"`
	Instance string `json:"instance"`
	Status   int    `json:"status"`
	Error    string `json:"error"`
}

RFC7807Error represents RFC 7807 error.

Jump to

Keyboard shortcuts

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