Documentation ¶
Index ¶
- Constants
- func Get(url string, ret interface{}) error
- func Post(url string, req interface{}, ret interface{}) (err error)
- type ErrorType
- type Helper
- type Result
- func BadDataErr(err error, format string, args ...interface{}) *Result
- func Data(data interface{}) *Result
- func InternalErr(err error, format string, args ...interface{}) *Result
- func TestCall(t *testing.T, serveHTTP func(w http.ResponseWriter, req *http.Request), ...) (*require.Assertions, *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 Helper ¶ added in v0.2.0
type Helper struct {
// contains filtered or unexported fields
}
Helper provider some function to build a service
func NewHelper ¶ added in v0.2.0
func NewHelper(lg logrus.FieldLogger, register *prometheus.Registry, metricsPrefix string) *Helper
NewHelper create a new APIWrapper
func (*Helper) MetricsHandler ¶ added in v0.2.0
MetricsHandler process metrics request
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
func TestCall ¶
func TestCall(t *testing.T, serveHTTP func(w http.ResponseWriter, req *http.Request), uri, method, data string, ret interface{}) (*require.Assertions, *Result)
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
Click to show internal directories.
Click to hide internal directories.