Documentation ¶
Index ¶
- Constants
- func Get(url string, ret interface{}) error
- func Post(url string, req interface{}, ret interface{}) (err error)
- func TestCall(t *testing.T, engine *gin.Engine, uri, method, data string, ret interface{}) *require.Assertions
- func Wrap(log logrus.FieldLogger, f func(ctx *gin.Context) *Result) func(ctx *gin.Context)
- type ErrorType
- type Result
- type Status
Constants ¶
View Source
const ( // StatusSuccess indicate result Status is success, the data of result is available StatusSuccess Status = "success" // StatusError indicate result is failed, the data may be empty StatusError Status = "error" // ErrorBadData indicate that result is failed because the wrong request data ErrorBadData ErrorType = "bad_data" // ErrorInternal indicate that result is failed because the request data may be right but the server is something wrong ErrorInternal ErrorType = "internal" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Result ¶
type Result struct { // ErrorType is the type of result if Status is not success ErrorType ErrorType `json:"errorType,omitempty"` // Err indicate the error detail Err string `json:"error,omitempty"` // Data is the real data of result, data may be nil even if Status is success Data interface{} `json:"data,omitempty"` // Status indicate whether the result is success Status Status `json:"status"` }
Result is the common format of all response
func BadDataErr ¶
BadDataErr make a result with ErrorType ErrorBadData
func Data ¶
func Data(data interface{}) *Result
Data make a result with data or nil, the Status will be set to StatusSuccess
func InternalErr ¶
InternalErr make a result with ErrorType ErrorInternal
Click to show internal directories.
Click to hide internal directories.