json

package
v1.7.6 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2023 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 interface{}) (err error)

DecodeRequest decodes http request body.

func DecodeResponse added in v0.0.25

func DecodeResponse(res *http.Response, data interface{}) (err error)

DecodeResponse decodes http response body.

func EncodeRequest added in v0.0.25

func EncodeRequest(req *http.Request,
	data interface{}, contentTypes ...string,
) error

EncodeRequest encodes http request.

func EncodeResponse

func EncodeResponse(w http.ResponseWriter,
	data interface{}, 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 interface{}, logic func() (interface{},
		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 interface{}) error

Request sends http json request.

Types

type RFC7807Error

type RFC7807Error struct {
	Type     string      `json:"type"`
	Title    string      `json:"title"`
	Detail   interface{} `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