jresp

package module
v0.0.0-...-65e84ef Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2015 License: Apache-2.0 Imports: 4 Imported by: 7

README

golang-jresp

JSON response helper for GoLang (useful for REST API services)

Usage

jr := jresp.NewJsonResp()
jr.Set("name", "John Doe")
jr.OK()
jr.ToString(false) // Will print: {"parsetime":"1.988µs","ping":"pong","status":"OK"}

or in case of an error

jr := jresp.NewJsonResp()
jr.Error("Oops, something went wrong")
jr.ToString(false) // Will print:  {"parsetime":"1.988µs","error":"Oops, something went wrong","status":"ERROR"}

you can also pretty print

jr.ToString(true) // Will print the same JSON structure as usual, but then nicely formatted

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type JResp

type JResp struct {
	// contains filtered or unexported fields
}

func NewJsonResp

func NewJsonResp() *JResp

func (*JResp) Error

func (jr *JResp) Error(msg string)

func (*JResp) OK

func (jr *JResp) OK()

func (*JResp) Set

func (jr *JResp) Set(k string, v interface{})

func (*JResp) ToString

func (jr *JResp) ToString(prettyPrint bool) string

Jump to

Keyboard shortcuts

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