Documentation ¶
Index ¶
- Constants
- Variables
- func GetErrorCode(err error) string
- func GetHTTPCode(code string) int
- func StatusCode(code int) string
- func StatusText(code int) string
- type JSONResponse
- func (r *JSONResponse) APIStatusAccepted() *JSONResponse
- func (r *JSONResponse) APIStatusBadRequest() *JSONResponse
- func (r *JSONResponse) APIStatusCreated() *JSONResponse
- func (r *JSONResponse) APIStatusErrorUnknown() *JSONResponse
- func (r *JSONResponse) APIStatusForbidden() *JSONResponse
- func (r *JSONResponse) APIStatusInvalidAuthentication() *JSONResponse
- func (r *JSONResponse) APIStatusNotFound() *JSONResponse
- func (r *JSONResponse) APIStatusSuccess() *JSONResponse
- func (r *JSONResponse) APIStatusUnauthorized() *JSONResponse
- func (r *JSONResponse) GetBody() []byte
- func (r *JSONResponse) Send(w http.ResponseWriter)
- func (r *JSONResponse) SetData(data interface{}) *JSONResponse
- func (r *JSONResponse) SetError(err error, a ...string) *JSONResponse
- func (r *JSONResponse) SetHTML() *JSONResponse
- func (r *JSONResponse) SetLatency(latency float64) *JSONResponse
- func (r *JSONResponse) SetLog(key string, val interface{}) *JSONResponse
- func (r *JSONResponse) SetMessage(msg string) *JSONResponse
- func (r *JSONResponse) SetResult(result interface{}) *JSONResponse
Constants ¶
View Source
const ( StatusCodeGenericSuccess = "200000" StatusCodeBadRequest = "400000" StatusCodeAlreadyRegistered = "400001" StatusCodeForbidden = "403000" StatusCodeNotFound = "404000" StatusCodeConflict = "409000" StatusCodeGenericPreconditionFailed = "412000" StatusCodeOTPLimitReached = "412550" StatusCodeNoLinkerExist = "412553" StatusCodeInternalError = "500000" StatusCodeFailedSellBatch = "500100" StatusCodeFailedOTP = "503000" StatusCodeTimeoutError = "504000" )
View Source
const ( StatusCtxKey = 0 StatusSuccess = http.StatusOK StatusErrorForm = http.StatusBadRequest StatusErrorUnknown = http.StatusBadGateway StatusInternalError = http.StatusInternalServerError 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") ErrConflict = errors.New("conflict") )
Functions ¶
func GetErrorCode ¶
func GetHTTPCode ¶
func StatusCode ¶
func StatusText ¶
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
Click to show internal directories.
Click to hide internal directories.