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, serveHTTP func(w http.ResponseWriter, req *http.Request), ...) *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 ¶
func TestCall ¶
func TestCall(t *testing.T, serveHTTP func(w http.ResponseWriter, req *http.Request), uri, method, data string, ret interface{}) *require.Assertions
TestCall create a httptest server and do http request to it the data in params will be write to server and the ret in params is deemed to the Data of common Result
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.