response

package
v0.0.0-...-e31961d Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONError

type JSONError struct {
	Title   string   `json:"title"`
	Message string   `json:"message"`
	Detail  string   `json:"detail"`
	Errors  []string `json:"errors"`
}

JSONError struct for error field in json response

type JSONResponse

type JSONResponse struct {

	// response part
	ResponseStatus Status             `json:"status"`
	ResponseData   interface{}        `json:"data"`
	ResponseRetry  *JSONRetryResponse `json:"retry,omitempty"`
	ResponseError  *JSONError         `json:"error,omitempty"`
	// contains filtered or unexported fields
}

JSONResponse struct for http json response

func JSON

JSON create a new JSON response

func (*JSONResponse) Data

func (jresp *JSONResponse) Data(data interface{}) *JSONResponse

Data for set data to json response

func (*JSONResponse) Error

func (jresp *JSONResponse) Error(err error, errResp *JSONError) *JSONResponse

Error set error to json response only use error when the type of error is *xerrors.Error

func (*JSONResponse) SetHeader

func (jresp *JSONResponse) SetHeader(key, value string)

SetHeader used to set header in http.ResponseWriter of JSONResponse

func (*JSONResponse) Write

func (jresp *JSONResponse) Write() (int, error)

Write json response

func (*JSONResponse) WriteHeader

func (jresp *JSONResponse) WriteHeader(statusCode int) *JSONResponse

WriteHeader set the header of JSONResponse writer

type JSONRetryResponse

type JSONRetryResponse struct {
	RetryMin int `json:"retry_min"`
	RetryMax int `json:"retry_max"`
}

JSONRetryResponse struct for retry field in json response

type Status

type Status string

Status of json response

const (
	StatusOK            Status = "OK"
	StatusRetry         Status = "RETRY"
	StatusBadRequest    Status = "BAD_REQUEST"
	StatusNotFound      Status = "NOT_FOUND"
	StatusUnauthorized  Status = "UNAUTHORIZED"
	StatusInternalError Status = "INTERNAL_ERROR"
)

list of status for http response

Jump to

Keyboard shortcuts

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