go-serializer: github.com/kataras/go-serializer Index | Files | Directories

package serializer

import "github.com/kataras/go-serializer"

Package serializer helps GoLang Developers to serialize any custom type to []byte or string. Your custom serializers are finally, organised.

Built'n supported serializers: JSON, JSONP, XML, Markdown.

This package is already used by Iris web framework.

Index

Package Files

serializer.go

Constants

const NotAllowedKeyChar = '.'

NotAllowedKeyChar the rune which is not allowed to be inside a serializer key string this exists because almost all package's users will use kataras/go-template with kataras/go-serializer in one method, so we need something to tell if the 'renderer' wants to render a serializer's result or the template's result, you don't have to worry about these things.

const (
    // Version current version number
    Version = "0.0.5"
)

func For Uses

func For(key string, serializer ...Serializer)

For puts a serializer(s) to the map

func Len Uses

func Len() int

Len returns the length of the serializers map

func RegisterDefaults Uses

func RegisterDefaults(serializers Serializers)

RegisterDefaults register defaults serializer for each of the default serializer keys (data,json,jsonp,markdown,text,xml)

func Serialize Uses

func Serialize(key string, obj interface{}, options ...map[string]interface{}) ([]byte, error)

Serialize returns the result as bytes representation of the serializer(s)

func SerializeToString Uses

func SerializeToString(key string, obj interface{}, options ...map[string]interface{}) (string, error)

SerializeToString returns the string representation of the serializer(s) same as Serialize but returns string

type Options Uses

type Options map[string]interface{}

Options is just a shortcut of a map[string]interface{}, which can be passed to the Serialize/SerializeToString funcs

type SerializeFunc Uses

type SerializeFunc func(interface{}, ...map[string]interface{}) ([]byte, error)

SerializeFunc is the alternative way to implement a Serializer using a simple function

func (SerializeFunc) Serialize Uses

func (s SerializeFunc) Serialize(obj interface{}, options ...map[string]interface{}) ([]byte, error)

Serialize accepts an object with serialization options and returns its bytes representation

type Serializer Uses

type Serializer interface {
    // Serialize accepts an object with serialization options and returns its bytes representation
    Serialize(interface{}, ...map[string]interface{}) ([]byte, error)
}

Serializer is the interface which all serializers should implement

type Serializers Uses

type Serializers map[string][]Serializer

Serializers is optionally, used when your app needs to manage more than one serializer keeps a map with a key of the ContentType(or any string) and a collection of Serializers

if a ContentType(key) has more than one serializer registered to it then the final result will be all of the serializer's results combined

func (Serializers) For Uses

func (s Serializers) For(key string, serializer ...Serializer)

For puts a serializer(s) to the map

func (Serializers) Len Uses

func (s Serializers) Len() int

Len returns the length of the serializers map

func (Serializers) Serialize Uses

func (s Serializers) Serialize(key string, obj interface{}, options ...map[string]interface{}) ([]byte, error)

Serialize returns the result as bytes representation of the serializer(s)

func (Serializers) SerializeToString Uses

func (s Serializers) SerializeToString(key string, obj interface{}, options ...map[string]interface{}) (string, error)

SerializeToString returns the string representation of the serializer(s) same as Serialize but returns string

Directories

PathSynopsis
json
jsonp
markdown
xml

Package serializer imports 7 packages (graph) and is imported by 7 packages. Updated 2017-08-14. Refresh now. Tools for package owners.