response

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: Apache-2.0 Imports: 1 Imported by: 0

README

response

response is a wrapper that is used for wrapping response for http response.

Usage Example

for normal case

    r := response.NewJSONResponse().
		WithCode("SUCCESS").
		WithData(u).
		WithMessage("some message").
		WithResult(map[string]interface{}{
			"amount": 1,
		}).
		WithLatency(now)

if we want to set up error message on response

    r := response.NewJSONResponse().
		WithErrorString("some error")

you can find some example in example/response_example

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JSONResponse

type JSONResponse struct {
	Data        interface{} `json:"data,omitempty"`
	Message     string      `json:"message,omitempty"`
	Code        string      `json:"code,omitempty"`
	StatusCode  int         `json:"status_code,omitempty"`
	ErrorString string      `json:"error,omitempty"`
	Latency     int64       `json:"latency,omitempty"`
	Result      interface{} `json:"result,omitempty"`
}

func NewJSONResponse

func NewJSONResponse() JSONResponse

func (JSONResponse) WithCode

func (r JSONResponse) WithCode(code string) JSONResponse

func (JSONResponse) WithData

func (r JSONResponse) WithData(data interface{}) JSONResponse

func (JSONResponse) WithErrorString

func (r JSONResponse) WithErrorString(errorStr string) JSONResponse

func (JSONResponse) WithLatency

func (r JSONResponse) WithLatency(start time.Time) JSONResponse

func (JSONResponse) WithMessage

func (r JSONResponse) WithMessage(message string) JSONResponse

func (JSONResponse) WithResult

func (r JSONResponse) WithResult(result interface{}) JSONResponse

func (JSONResponse) WithStatusCode

func (r JSONResponse) WithStatusCode(statusCode int) JSONResponse

Jump to

Keyboard shortcuts

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