jsend

package
v1.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

README

jsend

Implements the JSend specification for gin. See JSend specification for details.

Usage

func (h Health) Status(c *gin.Context) {
  data := gin.H{"application": gin.H{"version": "20190808"}}
  resp := jsend.R{CTX: c, StatusCode: http.StatusOK, Data: data}
  resp.JSON()
}

The above will output the following JSON encoded message:

{
  "status": "success",
  "data": {
    "application": {
      "version": "20190808"
    }
  }
}

Thanks

Documentation

Index

Constants

View Source
const (
	StatusSuccess = "success"
	StatusError   = "error"
	StatusFail    = "fail"
)

Variables

This section is empty.

Functions

func JSONStatusBadRequest

func JSONStatusBadRequest(c *gin.Context, data interface{})

func JSONStatusCreated

func JSONStatusCreated(c *gin.Context, data interface{})

func JSONStatusNotFound

func JSONStatusNotFound(c *gin.Context, data interface{})

func JSONStatusOK

func JSONStatusOK(c *gin.Context, data interface{})

func JSONStatusServerError

func JSONStatusServerError(c *gin.Context, data interface{}, message string, code int)

func JSONStatusServerMError

func JSONStatusServerMError(c *gin.Context, err error)

Types

type R

type R = Response

R is a shortcut for Response

func (R) JSON

func (resp R) JSON()

JSON implements the JSend specification (https://labs.omniti.com/labs/jsend).

type Response

type Response struct {
	CTX        *gin.Context `json:"-"`
	StatusCode int          `json:"-"`
	Status     string       `json:"status"`
	Data       interface{}  `json:"data"`
	Message    string       `json:"message,omitempty"`
	Code       int          `json:"code,omitempty"`
}

Jump to

Keyboard shortcuts

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