No description, website, or topics provided.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
.travis.yml
Makefile
README.md
gowebresponse.go
gowebresponse_test.go

README.md

Support with donation

Support with donation

gowebresponse

Golang WebRespone class for web and service

With this library you can always send the same json structure to your web response, it turn development very fast and easy because to other part always know what it will receive

CI

Build Status

Installing

go get github.com/prsolucoes/gowebresponse

Importing into your project

import "github.com/prsolucoes/gowebresponse"

How to use

func ExampleHowToUse() {
	// initializing
	wr := NewGoWebResponse()

	// adding data
	wr.AddData("name", "Paulo")
	wr.AddData("age", "30")

	// clear data
	wr.ClearData()

	// adding data on error and validate message
	wr.Message = "validate"
	wr.AddDataError("name", "Name field cannot be empty")
	wr.AddDataError("email", "Email is invalid")

	// clear error data
	wr.ClearDataErrors()

	// clear message
	wr.Message = ""

	// get json as string
	jsonData, _ := wr.ToString()
	fmt.Print(jsonData)

	// Output: {"success":false,"message":"","data":{"errors":[]}}
}

Obs: There is a test method to use all methods

Test

make test

or

go test -v

Thanks.