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
- func For(key string, serializer ...Serializer)
- func Len() int
- func RegisterDefaults(serializers Serializers)
- func Serialize(key string, obj interface{}, options ...map[string]interface{}) ([]byte, error)
- func SerializeToString(key string, obj interface{}, options ...map[string]interface{}) (string, error)
- type Options
- type SerializeFunc
- type Serializer
- type Serializers
- func (s Serializers) For(key string, serializer ...Serializer)
- func (s Serializers) Len() int
- func (s Serializers) Serialize(key string, obj interface{}, options ...map[string]interface{}) ([]byte, error)
- func (s Serializers) SerializeToString(key string, obj interface{}, options ...map[string]interface{}) (string, error)
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.4"
)
Variables ¶
This section is empty.
Functions ¶
func RegisterDefaults ¶
func RegisterDefaults(serializers Serializers)
RegisterDefaults register defaults serializer for each of the default serializer keys (data,json,jsonp,markdown,text,xml)
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 ¶
SerializeFunc is the alternative way to implement a Serializer using a simple function
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