toJson

package module
v0.0.0-...-09ad455 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2018 License: MIT Imports: 8 Imported by: 1

README

Simple helper to write json representations of structs to a http response.

In essence, the toJson.ToJson Method converts whatever interface is provided to a representation based
entirely on Slices/Maps/Primitive types.

If type implements the JsonWriter interface, the output of it is used instead of the normal algorithm.

Normal usage is

    err := toJson.WriteToJson(w, obj)


If you already have a marshable datatype, you can use toJson.WriteJson directly.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Debug bool = false
View Source
var Logger *logrus.Logger
View Source
var ReflectTypeError = errors.New("Got passed reflect.Type")
View Source
var ReflectValueError = errors.New("Got passed reflect.Value")
View Source
var TypeError = errors.New("Could not get type")
View Source
var UnsupportedDatatype = errors.New("Unsupported Datatype")

Functions

func ToJson

func ToJson(i interface{}) (interface{}, error)

func WriteJson

func WriteJson(w http.ResponseWriter, obj interface{}, code int) error

func WriteToJson

func WriteToJson(w http.ResponseWriter, obj interface{}) error

func WriteToJsonNotWrapped

func WriteToJsonNotWrapped(w http.ResponseWriter, obj interface{}) error

func WriteToJsonNotWrappedWithCode

func WriteToJsonNotWrappedWithCode(w http.ResponseWriter, obj interface{}, code int) error

func WriteToJsonWithCode

func WriteToJsonWithCode(w http.ResponseWriter, obj interface{}, code int) error

Types

type JsonWriter

type JsonWriter jsonWriter

Jump to

Keyboard shortcuts

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