httputil

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpectFailure

func ExpectFailure(t *testing.T, resp *httptest.ResponseRecorder)

ExpectFailure asserts that given response is a failure response.

func ExpectSuccess

func ExpectSuccess(t *testing.T, resp *httptest.ResponseRecorder)

ExpectSuccess asserts that given response is a success response.

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.

Types

type ResponseOption

type ResponseOption func(h gin.H)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL