serialize

package
v0.0.0-...-ba7cdbd Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2014 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package serialize provides conveniency functions for serializing values to either JSON or XML

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Write

func Write(w io.Writer, value interface{}, f Format) (int, error)

Write serializes value using the Format f and writes it to w. If w also implements http.ResponseWriter, it sets the appropiate headers too. Returns the number of bytes written and any error that might occur while serializing or writing the serialized data.

func WriteJSON

func WriteJSON(w io.Writer, value interface{}) (int, error)

WriteJSON is equivalent to Write(w, value, JSON)

func WriteXML

func WriteXML(w io.Writer, value interface{}) (int, error)

WriteXML is equivalent to Write(w, value, XML)

Types

type Format

type Format int

Format indicates the format used to serialize an object.

const (
	// Serialize to JSON
	JSON Format = iota
	// Serialize to XML
	XML
)

type JSONWriter

type JSONWriter interface {
	// WriteJSON writes the object encoded as JSON into
	// the given io.Writer, returning the number of bytes
	// written and any potential errors.
	WriteJSON(w io.Writer) (int, error)
}

JSONWriter is the interface implemented by types which can write themselves as JSON into an io.Writer. You can use the gondola command for generating the code to implement this interface in your own types.

Jump to

Keyboard shortcuts

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