Giter Club home page Giter Club logo

rest-go's Introduction

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/Briofy/respond.go

Usage

import package

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

create respond instance

// argument rw is http.ResponseWriter or 
// gin.Writer if youre using gin-gonic
var jspon = respond.NewWithWriter(rw)

// or if you want to use custom languages
var jspon = respond.NewWithWriter(rw).Language("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(http.StatusOK).setStatusText("Success.").RespondWithMessage("Your custom message")

License

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.