Documentation ¶
Index ¶
- Constants
- func NewHTTPAddressFromContext(c *cli.Context) string
- func NewHTTPCliFlags(defaultPort HTTPPort) []cli.Flag
- func ResponseFailure(c *gin.Context, options ...ResponseOption)
- func ResponseSuccess(c *gin.Context, options ...ResponseOption)
- func RunHTTPTestCase(t *testing.T, tc HTTPTestCase, handler http.Handler)
- type AssertFn
- type CommonError
- type HTTPPort
- type HTTPTestCase
- type ResponseOption
Constants ¶
const (
// PortFlag string for flag port
PortFlag = "port"
)
Variables ¶
This section is empty.
Functions ¶
func NewHTTPAddressFromContext ¶
func NewHTTPAddressFromContext(c *cli.Context) string
NewHTTPAddressFromContext returns the configured address to listen to from cli flags configuration.
func NewHTTPCliFlags ¶
func NewHTTPCliFlags(defaultPort HTTPPort) []cli.Flag
NewHTTPCliFlags creates new cli flags for HTTP Server.
func ResponseFailure ¶
func ResponseFailure(c *gin.Context, options ...ResponseOption)
ResponseFailure responses the request with 200 status code and a failure message.
func ResponseSuccess ¶
func ResponseSuccess(c *gin.Context, options ...ResponseOption)
ResponseSuccess responses the request with 200 status code and a success message.
func RunHTTPTestCase ¶
func RunHTTPTestCase(t *testing.T, tc HTTPTestCase, handler http.Handler)
RunHTTPTestCase run http request test case.
Types ¶
type AssertFn ¶
type AssertFn func(t *testing.T, resp *httptest.ResponseRecorder)
AssertFn is the function used to asserts the test response.
func AssertCode ¶
AssertCode asserts that the response matched the expected error code.
type CommonError ¶
type CommonError struct {
Error string `json:"error"`
}
type HTTPPort ¶
type HTTPPort int
HTTPPort define custom type for port
const (
Port HTTPPort = 8030
)
type HTTPTestCase ¶
type HTTPTestCase struct { Msg string Endpoint string Method string Params map[string]string Body []byte Assert AssertFn }
HTTPTestCase struct for http test case.
type ResponseOption ¶
ResponseOption is the additional data to include in response.
func WithData ¶
func WithData(data interface{}) ResponseOption
WithData includes the given data to the response.
func WithError ¶
func WithError(err error) ResponseOption
WithError includes the error as a failure reason. It is usually used along with ResponseFailure. If err is nil, empty reason will be used.
func WithField ¶
func WithField(k string, v interface{}) ResponseOption
WithField includes the given field in the response.
func WithMultipleFields ¶
func WithMultipleFields(extra gin.H) ResponseOption
WithMultipleFields includes the extra data to the response.
func WithReason ¶
func WithReason(reason string) ResponseOption
WithReason includes the given reason to the response. It is intended to use for operation failed response.