Skip to content

mhosseintaher/respond.go

 
 

Repository files navigation

Go Respond

This package is provided to be used on golang and it gives clean methods to handle json response with specific predetermined messages.

Install

$ go get github.com/mrjosh/respond.go

Usage

import package

import "github.com/mrjosh/respond.go"

create respond instance

var jspon = respond.Default

// or if you want to use custom languages
var jspon = respond.DefaultWithLang("fa")

Some are shown below:

When request succeeds and contains data to return as a result:

jspon.Succeed(map[string] interface{} {
    "some_key": "some_data"
})

When deletion action succeeds:

jspon.DeleteSucceeded()

When updating succeeds:

jspon.UpdateSucceeded()

When insertion succeeds:

jspon.InsertSucceeded()

When deletion action fails:

jspon.DeleteFaild()

When updating fails:

jspon.UpdateFaild()

when insertion fails:

jspon.InsertFaild()

Not Found Error:

jspon.NotFound()

When parameters entered are wrong:

jspon.WrongParameters()

When requested method is not allowed:

jspon.MethodNotAllowed()
jspon.RequestFieldNotFound()

Validation errors:

jspon.ValidationErrors(map[string] interface{} {
  "some_key": "some_validation_errors_data"
})

###customization You can do more:

jspon.SetStatusCode(200).setStatusText('Success.').RespondWithMessage('Your custom message')

License

The MIT License (MIT). Please see License File for more information.

About

👩‍💻 Easy peasy json response for gin-gonic router!

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%