Product Promotion
0x5a.live
for different kinds of informations and explorations.
GitHub - clevergo/jsend: :100: JSend's implementation writen in Go(golang)
:100: JSend's implementation writen in Go(golang). Contribute to clevergo/jsend development by creating an account on GitHub.
Visit SiteGitHub - clevergo/jsend: :100: JSend's implementation writen in Go(golang)
:100: JSend's implementation writen in Go(golang). Contribute to clevergo/jsend development by creating an account on GitHub.
Powered by 0x5a.live ๐
JSend's implementation writen in Go(golang)
This package is an implementation of JSend specification written in Go(golang).
Installation
go get clevergo.tech/jsend
Usage
Usage is pretty simple.
// success response
jsend.Success(w, data)
// fail response
jsend.Fail(w, data)
// error response
jsend.Error(w, message)
// error response with extra code
jsend.ErrorCode(w, message, code)
// error response with extra code and data
jsend.ErrorCodeData(w, message, code, data)
It can also be integrated with web framework, such as Gin, Echo, CleverGo:
// success response
ctx.JSON(http.StatusOK, jsend.New(data))
// fail response
ctx.JSON(http.StatusOK, jsend.NewFail(data))
// error response
ctx.JSON(http.StatusOK, jsend.NewError(message, code, data))
Checkout example for details.
Error Handling
It is application responsibility to handle error.
Status Code
By default status code http.StatusOK
was used implicitly,
it can also be specified by the last parameter if necessary.
jsend.Success(w, data, http.StatusOK)
jsend.Fail(w, data, http.StatusForbidden)
jsend.Error(w, message, http.StatusInternalServerError)
GoLang Resources
are all listed below.
Made with โค๏ธ
to provide different kinds of informations and resources.