serializer

package module
v0.0.0-...-c81d399 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2018 License: MIT Imports: 9 Imported by: 1

Documentation

Overview

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, Text, Binary Data.

This package is already used by Iris & Q Web Frameworks.

Index

Constants

View Source
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.

View Source
const (
	// Version current version number
	Version = "0.0.4"
)

Variables

This section is empty.

Functions

func For

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

For puts a serializer(s) to the map

func Len

func Len() int

Len returns the length of the serializers map

func RegisterDefaults

func RegisterDefaults(serializers Serializers)

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

func Serialize

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

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

Types

type Options

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

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

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

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

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

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

For puts a serializer(s) to the map

func (Serializers) Len

func (s Serializers) Len() int

Len returns the length of the serializers map

func (Serializers) Serialize

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

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

Path Synopsis

Jump to

Keyboard shortcuts

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