response

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2024 License: CC0-1.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusCodeGenericSuccess            = "200000"
	StatusCodeBadRequest                = "400000"
	StatusCodeAlreadyRegistered         = "400001"
	StatusCodeUnauthorized              = "401000"
	StatusCodeForbidden                 = "403000"
	StatusCodeNotFound                  = "404000"
	StatusCodeConflict                  = "409000"
	StatusCodeGenericPreconditionFailed = "412000"
	StatusCodeOTPLimitReached           = "412550"
	StatusCodeNoLinkerExist             = "412553"
	StatusCodeInternalError             = "500000"
	StatusCodeFailedSellBatch           = "500100"
	StatusCodeFailedOTP                 = "503000"
	StatusCodeServiceUnavailable        = "503000"
	StatusCodeTimeoutError              = "504000"
)
View Source
const (
	StatusCtxKey                = 0
	StatusSuccess               = http.StatusOK
	StatusErrorForm             = http.StatusBadRequest
	StatusErrorUnknown          = http.StatusBadGateway
	StatusInternalError         = http.StatusInternalServerError
	StatusUnauthorized          = http.StatusUnauthorized
	StatusCreated               = http.StatusCreated
	StatusAccepted              = http.StatusAccepted
	StatusForbidden             = http.StatusForbidden
	StatusInvalidAuthentication = http.StatusProxyAuthRequired
	StatusNotFound              = http.StatusNotFound
)

Variables

View Source
var (
	ErrBadRequest          = errors.New("bad request")
	ErrForbiddenResource   = errors.New("forbidden resource")
	ErrNotFound            = errors.New("not found")
	ErrPreConditionFailed  = errors.New("precondition failed")
	ErrInternalServerError = errors.New("internal server error")
	ErrTimeoutError        = errors.New("timeout error")
	ErrUnauthorized        = errors.New("unauthorized")
	ErrConflict            = errors.New("conflict")
)

Functions

func GetErrorCode

func GetErrorCode(err error) string

func GetHTTPCode

func GetHTTPCode(code string) int

func StatusCode

func StatusCode(code int) string

func StatusText

func StatusText(code int) string

Types

type JSONResponse

type JSONResponse struct {
	Data        interface{}            `json:"data,omitempty"`
	Message     string                 `json:"message,omitempty"`
	Code        string                 `json:"code"`
	StatusCode  int                    `json:"statusCode"`
	ErrorString string                 `json:"error,omitempty"`
	Error       error                  `json:"-"`
	RealError   string                 `json:"-"`
	Latency     string                 `json:"latency"`
	Log         map[string]interface{} `json:"-"`
	HTMLPage    bool                   `json:"-"`
	Result      interface{}            `json:"result,omitempty"`
}

func NewJSONResponse

func NewJSONResponse() *JSONResponse

func (*JSONResponse) APIStatusAccepted

func (r *JSONResponse) APIStatusAccepted() *JSONResponse

APIStatusAccepted

func (*JSONResponse) APIStatusBadRequest

func (r *JSONResponse) APIStatusBadRequest() *JSONResponse

APIStatusBadRequest

func (*JSONResponse) APIStatusCreated

func (r *JSONResponse) APIStatusCreated() *JSONResponse

APIStatusCreated

func (*JSONResponse) APIStatusErrorUnknown

func (r *JSONResponse) APIStatusErrorUnknown() *JSONResponse

APIStatusErrorUnknown

func (*JSONResponse) APIStatusForbidden

func (r *JSONResponse) APIStatusForbidden() *JSONResponse

APIStatusForbidden

func (*JSONResponse) APIStatusInvalidAuthentication

func (r *JSONResponse) APIStatusInvalidAuthentication() *JSONResponse

APIStatusInvalidAuthentication

func (*JSONResponse) APIStatusNotFound

func (r *JSONResponse) APIStatusNotFound() *JSONResponse

APIStatusNotFound

func (*JSONResponse) APIStatusSuccess

func (r *JSONResponse) APIStatusSuccess() *JSONResponse

APIStatusSuccess for standard request api status success

func (*JSONResponse) APIStatusUnauthorized

func (r *JSONResponse) APIStatusUnauthorized() *JSONResponse

APIStatusUnauthorized

func (*JSONResponse) GetBody

func (r *JSONResponse) GetBody() []byte

func (*JSONResponse) Send

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

func (*JSONResponse) SetData

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

func (*JSONResponse) SetError

func (r *JSONResponse) SetError(err error, a ...string) *JSONResponse

func (*JSONResponse) SetHTML

func (r *JSONResponse) SetHTML() *JSONResponse

func (*JSONResponse) SetLatency

func (r *JSONResponse) SetLatency(latency float64) *JSONResponse

func (*JSONResponse) SetLog

func (r *JSONResponse) SetLog(key string, val interface{}) *JSONResponse

func (*JSONResponse) SetMessage

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

func (*JSONResponse) SetResult

func (r *JSONResponse) SetResult(result interface{}) *JSONResponse

Jump to

Keyboard shortcuts

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