Documentation ¶
Overview ¶
Package json provides helpers to work with JSON.
Index ¶
- Variables
- type JSON
- func (j *JSON) ErrorJSON(w http.ResponseWriter, err error, status ...int) error
- func (j *JSON) PushJSONToRemote(uri string, data any, client ...*http.Client) (*http.Response, int, error)
- func (j *JSON) ReadJSON(w http.ResponseWriter, r *http.Request, data any) error
- func (j *JSON) WriteJSON(w http.ResponseWriter, status int, data any, headers ...http.Header) error
- type JSONResponse
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrDecodeJSON = errors.New("json: error decoding json data") ErrMultipleJSONValue = errors.New("json: body must have only a single json value") )
Functions ¶
This section is empty.
Types ¶
type JSON ¶
func (*JSON) ErrorJSON ¶
ErrorJSON takes an error and optionally a status code, generates and send a JSON error message.
func (*JSON) PushJSONToRemote ¶
func (j *JSON) PushJSONToRemote(uri string, data any, client ...*http.Client) (*http.Response, int, error)
PushJSONToRemote posts arbitrary data to a remote URL as JSON, and returns the response, status code and error if any. The final parameter client is optional. If none is specified, we use the standard http.Client.
type JSONResponse ¶
type JSONResponse struct { Error bool `json:"error"` Message string `json:"message"` Data any `json:"data,omitempty"` }
JSONResponse is the type used for sending JSON.
Click to show internal directories.
Click to hide internal directories.