response

package
v0.0.0-...-0aa8bca Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const CSVContentType = "text/csv"
View Source
const JSONContentType = "application/json"

Variables

View Source
var (
	ErrorInternalServer    = NewError("Internal Server Error", http.StatusInternalServerError)
	ErrorForbiddenResource = NewError("Forbidden Resource", http.StatusForbidden)
	ErrorBadRequest        = NewError("Bad Request", http.StatusBadRequest)
)

Functions

This section is empty.

Types

type BasicResponse

type BasicResponse struct {
	Body        []byte
	StatusCode  int
	ContentType string
}

func (*BasicResponse) WriteResponse

func (b *BasicResponse) WriteResponse(w http.ResponseWriter)

type CSVBody

type CSVBody struct {
	*Error
	Name string
}

type CSVResponse

type CSVResponse struct {
	BasicResponse
	CSVBody CSVBody
	Error   error
}

func NewCSVResponse

func NewCSVResponse() *CSVResponse

func (*CSVResponse) SetData

func (r *CSVResponse) SetData(data []byte) *CSVResponse

func (*CSVResponse) SetName

func (r *CSVResponse) SetName(name string) *CSVResponse

func (*CSVResponse) WriteResponse

func (r *CSVResponse) WriteResponse(w http.ResponseWriter)

type Error

type Error struct {
	ErrorMessage string `json:"error,omitempty"`
	ErrorCode    int    `json:"error_code,omitempty"`
}

func NewError

func NewError(message string, code int) *Error

func (*Error) Error

func (re *Error) Error() string

type HTTPResponse

type HTTPResponse interface {
	WriteResponse(w http.ResponseWriter)
}

type JSONBody

type JSONBody struct {
	*Error
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

type JSONResponse

type JSONResponse struct {
	BasicResponse
	JSONBody JSONBody
	Error    error
}

func NewJSONResponse

func NewJSONResponse() *JSONResponse

func (*JSONResponse) SetData

func (r *JSONResponse) SetData(data interface{}) *JSONResponse

func (*JSONResponse) SetError

func (r *JSONResponse) SetError(err error) *JSONResponse

func (*JSONResponse) SetMessage

func (r *JSONResponse) SetMessage(message string) *JSONResponse

func (*JSONResponse) WriteResponse

func (r *JSONResponse) WriteResponse(w http.ResponseWriter)

Jump to

Keyboard shortcuts

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