transit

package module
v0.0.0-...-0794b4c Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2018 License: Apache-2.0 Imports: 16 Imported by: 9

README

transit (go)

GoDoc

Transit is a data format and a set of libraries for conveying values between applications written in different languages. This library provides support for marshalling Transit data to/from Go.

This implementation's major.minor version number corresponds to the version of the Transit specification it supports.

Currently on the JSON formats are implemented. MessagePack is not implemented yet.

NOTE: Transit is a work in progress and may evolve based on feedback. As a result, while Transit is a great option for transferring data between applications, it should not yet be used for storing data durably over time. This recommendation will change when the specification is complete.

Usage

Reading data with Transit(go) involves creating a transit.Decoder and calling Decode:

package main

import (
	"fmt"
	"os"
	"github.com/russolsen/transit"
)

func ReadTransit(path string) interface{} {
	f, err := os.Open(path)

	if err != nil {
		fmt.Printf("Error opening file: %v\n", err)
		return nil
	}

	decoder := transit.NewDecoder(f)

	value, err := decoder.Decode()

	if err != nil {
		fmt.Printf("Error reading Transit data: %v\n", err)
		return nil
	}

	fmt.Printf("The value read is: %v\n", value)

	return value
}

Writing is similar:

func WriteTransit(path string, value interface{}) {
	f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777)

	if err != nil {
		fmt.Printf("Error opening file: %v\n", err)
		return
	}

	encoder := transit.NewEncoder(f, false)

	err = encoder.Encode(value)

	if err != nil {
		fmt.Printf("Error writing Transit data: %v\n", err)
		return
	}
}

Default Type Mapping

Semantic Type write accepts read produces
null nil nil
string string string
boolean bool bool
integer, signed 64 bit any signed or unsiged int type int64
floating pt decimal float32 or float64 float64
bytes []byte []byte
keyword transit.Keyword transit.Keyword
symbol transit.Symbol transit.Keyword
arbitrary precision decimal big.Float or github.com/shopspring/decimal.Decimal github.com/shopspring/decimal.Decimal
arbitrary precision integer big.Int big.Int
point in time time.Time time.Time
point in time RFC 33339 - time.Time
u github.com/pborman/uuid UUID github.com/pborman/uuid UUID
uri net/url URL net/url URL
char rune rune
special numbers As defined by math NaN and math.Inf() TBD
array arrays or slices []interface{}
map map[interface{}]interface{} map[interface{}]interface{}
set transit.Set transit.Set
list container/list List container/list List
map w/ composite keys transit.CMap transit.CMap
link transit.Link transit.Link
ratio big.Rat big.Rat

Copyright © 2016 Russ Olsen

This library is a Go port of the Java version created and maintained by Cognitect, therefore

Copyright © 2014 Cognitect

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This README file is based on the README from transit-csharp, therefore:

Copyright © 2014 NForza.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Index

Constants

View Source
const MaxJsonInt = 1<<53 - 1

Variables

This section is empty.

Functions

func DecodeBigInteger

func DecodeBigInteger(d Decoder, x interface{}) (interface{}, error)

DecodeBigInteger decodes a transit big integer into a Go big.Int.

func DecodeBoolean

func DecodeBoolean(d Decoder, x interface{}) (interface{}, error)

DecodeBoolean decodes a transit boolean into a Go bool.

func DecodeByte

func DecodeByte(d Decoder, x interface{}) (interface{}, error)

DecodeRatio decodes a transit base64 encoded byte array into a Go byte array.

func DecodeCMap

func DecodeCMap(d Decoder, x interface{}) (interface{}, error)

DecodeCMap decodes maps with composite keys.

func DecodeDecimal

func DecodeDecimal(d Decoder, x interface{}) (interface{}, error)

DecodeDecimal decodes a transit big decimal into decimal.Decimal.

func DecodeFloat

func DecodeFloat(d Decoder, x interface{}) (interface{}, error)

DecodeFloat decodes the value into a float.

func DecodeFromString

func DecodeFromString(s string) (interface{}, error)

DecodeFromString is a handly function that decodes Transit data held in a string.

func DecodeIdentity

func DecodeIdentity(d Decoder, x interface{}) (interface{}, error)

DecodeIdentity returns the value unchanged.

func DecodeInteger

func DecodeInteger(d Decoder, x interface{}) (interface{}, error)

DecodeInteger decodes a transit integer into a plain Go int64

func DecodeKeyword

func DecodeKeyword(d Decoder, x interface{}) (interface{}, error)

DecodeKeyword decodes ~: style keywords.

func DecodeLink(d Decoder, x interface{}) (interface{}, error)

DecodeLink decodes a transit link into an instance of Link.

func DecodeList

func DecodeList(d Decoder, x interface{}) (interface{}, error)

DecodeList decodes a transit list into a Go list.

func DecodeNil

func DecodeNil(d Decoder, x interface{}) (interface{}, error)

DecodeRatio decodes a transit null/nil.

func DecodeQuote

func DecodeQuote(d Decoder, x interface{}) (interface{}, error)

DecodeQuote decodes a transit quoted value by simply returning the value.

func DecodeRFC3339

func DecodeRFC3339(d Decoder, x interface{}) (interface{}, error)

DecodeRFC3339 decodes a time value into a Go time instance. TBD not 100% this covers all possible values.

func DecodeRatio

func DecodeRatio(d Decoder, x interface{}) (interface{}, error)

DecodeRatio decodes a transit ratio into a Go big.Rat.

func DecodeRune

func DecodeRune(d Decoder, x interface{}) (interface{}, error)

DecodeRune decodes a transit char.

func DecodeSet

func DecodeSet(d Decoder, x interface{}) (interface{}, error)

DecodeSet decodes a transit set into a transit.Set instance.

func DecodeSpecialNumber

func DecodeSpecialNumber(d Decoder, x interface{}) (interface{}, error)

DecodeSpecialNumber decodes NaN, INF and -INF into their Go equivalents.

func DecodeSymbol

func DecodeSymbol(d Decoder, x interface{}) (interface{}, error)

DecodeKeyword decodes ~$ style symbols.

func DecodeTime

func DecodeTime(d Decoder, x interface{}) (interface{}, error)

DecodeTime decodes a time value represended as millis since 1970.

func DecodeURI

func DecodeURI(d Decoder, x interface{}) (interface{}, error)

DecodeURI decodes a transit URI into an instance of TUri.

func DecodeUUID

func DecodeUUID(d Decoder, x interface{}) (interface{}, error)

DecodeUUID decodes a transit UUID into an instance of net/UUID

func EncodeToString

func EncodeToString(x interface{}, verbose bool) (string, error)

Encode the given value to a string.

func Equals

func Equals(a, b interface{}) bool

Matches keys with a simple == test. Satisfies the MatchF protocol.

func GetElement

func GetElement(array reflect.Value, i int) reflect.Value

GetElement pulls a value out of a array (represented by the array value). This function differs from the reflect.Value Index in that the type and kind of the returned value reflect the type and kind of the element, not what was declared in the array.

func GetMapElement

func GetMapElement(m reflect.Value, key reflect.Value) reflect.Value

GetMapElement pulls a value out of a map (represented by the m value). This function differs from the reflect.Value MapIndex in that the type and kind of the returned value reflect the type and kind of the element, not what was declared in the map.

func IsGenericArray

func IsGenericArray(x interface{}) bool

func KeyValues

func KeyValues(m reflect.Value) []reflect.Value

KeyValues returns the Values for the keys in a map.

Types

type ArrayEncoder

type ArrayEncoder struct{}

func NewArrayEncoder

func NewArrayEncoder() *ArrayEncoder

func (ArrayEncoder) Encode

func (ie ArrayEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (ArrayEncoder) IsStringable

func (ie ArrayEncoder) IsStringable(v reflect.Value) bool

type BigFloatEncoder

type BigFloatEncoder struct{}

func NewBigFloatEncoder

func NewBigFloatEncoder() *BigFloatEncoder

func (BigFloatEncoder) Encode

func (ie BigFloatEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (BigFloatEncoder) IsStringable

func (ie BigFloatEncoder) IsStringable(v reflect.Value) bool

type BigIntEncoder

type BigIntEncoder struct{}

func NewBigIntEncoder

func NewBigIntEncoder() *BigIntEncoder

func (BigIntEncoder) Encode

func (ie BigIntEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (BigIntEncoder) IsStringable

func (ie BigIntEncoder) IsStringable(v reflect.Value) bool

type BigRatEncoder

type BigRatEncoder struct{}

func NewBigRatEncoder

func NewBigRatEncoder() *BigRatEncoder

func (BigRatEncoder) Encode

func (ie BigRatEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (BigRatEncoder) IsStringable

func (ie BigRatEncoder) IsStringable(v reflect.Value) bool

type BoolEncoder

type BoolEncoder struct{}

func NewBoolEncoder

func NewBoolEncoder() *BoolEncoder

func (BoolEncoder) Encode

func (ie BoolEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (BoolEncoder) IsStringable

func (ie BoolEncoder) IsStringable(v reflect.Value) bool

type CMap

type CMap struct {
	Entries []CMapEntry
}

func NewCMap

func NewCMap() *CMap

func (*CMap) Append

func (cm *CMap) Append(key, value interface{}) *CMap

Append inserts a new key/value pair w/o paying attention to duplicate keys.

func (CMap) FindBy

func (cm CMap) FindBy(key interface{}, mf MatchF) *CMapEntry

func (CMap) Index

func (cm CMap) Index(keyValue interface{}) interface{}

func (CMap) Put

func (cm CMap) Put(key, value interface{}, mf MatchF) *CMap

func (*CMap) Size

func (cm *CMap) Size() int

Size returns the number of key/value pairs.

type CMapEncoder

type CMapEncoder struct{}

func NewCMapEncoder

func NewCMapEncoder() *CMapEncoder

func (CMapEncoder) Encode

func (ie CMapEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (CMapEncoder) IsStringable

func (ie CMapEncoder) IsStringable(v reflect.Value) bool

type CMapEntry

type CMapEntry struct {
	Key   interface{}
	Value interface{}
}

func NewCMapEntry

func NewCMapEntry(key, value interface{}) *CMapEntry

type Cache

type Cache interface {
	IsCacheable(s string, asKey bool) bool
	Write(string) string
}

Cache is the interface for (obviously) caches. Implemented by RollingCache and NoopCache.

type DataEmitter

type DataEmitter interface {
	Emit(s string) error
	EmitString(s string, cacheable bool) error
	EmitTag(s string) error
	EmitInt(i int64, asKey bool) error
	EmitFloat(f float64, asKey bool) error
	EmitNil(asKey bool) error
	EmitBool(bool, asKey bool) error
	EmitStartArray() error
	EmitArraySeparator() error
	EmitEndArray() error

	EmitStartMap() error
	EmitMapSeparator() error
	EmitKeySeparator() error
	EmitEndMap() error
}

type DecimalEncoder

type DecimalEncoder struct{}

func NewDecimalEncoder

func NewDecimalEncoder() *DecimalEncoder

func (DecimalEncoder) Encode

func (ie DecimalEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (DecimalEncoder) IsStringable

func (ie DecimalEncoder) IsStringable(v reflect.Value) bool

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new Decoder, ready to read from r.

func NewJsonDecoder

func NewJsonDecoder(jsd *json.Decoder) *Decoder

NewDecoder returns a new Decoder, ready to read from jsr.

func (Decoder) AddHandler

func (d Decoder) AddHandler(tag string, valueDecoder Handler)

AddHandler adds a new handler to the decoder, allowing you to extend the types it can handle.

func (Decoder) Decode

func (d Decoder) Decode() (interface{}, error)

Decode decodes the next Transit value from the stream.

func (Decoder) DecoderFor

func (d Decoder) DecoderFor(tagid TagId) Handler

func (Decoder) Parse

func (d Decoder) Parse(x interface{}, asKey bool) (interface{}, error)

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

func NewEncoder

func NewEncoder(w io.Writer, verbose bool) *Encoder

NewEncoder creates a new encoder set to writ to the stream supplied. The verbose parameter controls transit's verbose vs non-verbose mode. Generally for production you want verbose = false.

func (Encoder) AddHandler

func (e Encoder) AddHandler(t reflect.Type, c ValueEncoder)

AddHandler adds a new handler to the table used by this encoder for encoding values. The t value should be an instance of reflect.Type and the c value should be an encoder for that type.

func (Encoder) Encode

func (e Encoder) Encode(x interface{}) error

Encode a value at the top level.

func (Encoder) EncodeInterface

func (e Encoder) EncodeInterface(x interface{}, asKey bool) error

Given a raw interface, encode it.

func (Encoder) EncodeValue

func (e Encoder) EncodeValue(v reflect.Value, asKey bool) error

Given a Value, encode it.

func (Encoder) ValueEncoderFor

func (e Encoder) ValueEncoderFor(v reflect.Value) ValueEncoder

ValueEncoderFor finds the encoder for the given value.

type ErrorEncoder

type ErrorEncoder struct{}

func NewErrorEncoder

func NewErrorEncoder() *ErrorEncoder

func (ErrorEncoder) Encode

func (ie ErrorEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (ErrorEncoder) IsStringable

func (ie ErrorEncoder) IsStringable(v reflect.Value) bool

type FloatEncoder

type FloatEncoder struct{}

func NewFloatEncoder

func NewFloatEncoder() *FloatEncoder

func (FloatEncoder) Encode

func (ie FloatEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (FloatEncoder) IsStringable

func (ie FloatEncoder) IsStringable(v reflect.Value) bool

type Handler

type Handler func(Decoder, interface{}) (interface{}, error)

type IntEncoder

type IntEncoder struct{}

func NewIntEncoder

func NewIntEncoder() *IntEncoder

func (IntEncoder) Encode

func (ie IntEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (IntEncoder) IsStringable

func (ie IntEncoder) IsStringable(v reflect.Value) bool

type JsonEmitter

type JsonEmitter struct {
	// contains filtered or unexported fields
}

func NewJsonEmitter

func NewJsonEmitter(w io.Writer, cache Cache) *JsonEmitter

func (JsonEmitter) Emit

func (je JsonEmitter) Emit(s string) error

func (JsonEmitter) EmitArraySeparator

func (je JsonEmitter) EmitArraySeparator() error

func (JsonEmitter) EmitBase

func (je JsonEmitter) EmitBase(x interface{}) error

func (JsonEmitter) EmitBool

func (je JsonEmitter) EmitBool(x bool, asKey bool) error

func (JsonEmitter) EmitEndArray

func (je JsonEmitter) EmitEndArray() error

func (JsonEmitter) EmitEndMap

func (je JsonEmitter) EmitEndMap() error

func (JsonEmitter) EmitFloat

func (je JsonEmitter) EmitFloat(f float64, asKey bool) error

func (JsonEmitter) EmitInt

func (je JsonEmitter) EmitInt(i int64, asKey bool) error

func (JsonEmitter) EmitKeySeparator

func (je JsonEmitter) EmitKeySeparator() error

func (JsonEmitter) EmitMapSeparator

func (je JsonEmitter) EmitMapSeparator() error

func (JsonEmitter) EmitNil

func (je JsonEmitter) EmitNil(asKey bool) error

func (JsonEmitter) EmitStartArray

func (je JsonEmitter) EmitStartArray() error

func (JsonEmitter) EmitStartMap

func (je JsonEmitter) EmitStartMap() error

func (JsonEmitter) EmitString

func (je JsonEmitter) EmitString(s string, cacheable bool) error

func (JsonEmitter) EmitTag

func (je JsonEmitter) EmitTag(s string) error

type Keyword

type Keyword string

A Keyword is a transit keyword, really just a string by another type.

func (Keyword) String

func (k Keyword) String() string

type KeywordEncoder

type KeywordEncoder struct{}

func NewKeywordEncoder

func NewKeywordEncoder() *KeywordEncoder

func (KeywordEncoder) Encode

func (ie KeywordEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (KeywordEncoder) IsStringable

func (ie KeywordEncoder) IsStringable(v reflect.Value) bool
type Link struct {
	Href   *TUri
	Rel    string
	Name   string
	Prompt string
	Render string
}
func NewLink() *Link

type LinkEncoder

type LinkEncoder struct{}

func NewLinkEncoder

func NewLinkEncoder() *LinkEncoder

func (LinkEncoder) Encode

func (ie LinkEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (LinkEncoder) IsStringable

func (ie LinkEncoder) IsStringable(v reflect.Value) bool

type ListEncoder

type ListEncoder struct{}

func NewListEncoder

func NewListEncoder() *ListEncoder

func (ListEncoder) Encode

func (ie ListEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (ListEncoder) IsStringable

func (ie ListEncoder) IsStringable(v reflect.Value) bool

type MapEncoder

type MapEncoder struct {
	// contains filtered or unexported fields
}

func NewMapEncoder

func NewMapEncoder(verbose bool) *MapEncoder

func (MapEncoder) Encode

func (me MapEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (MapEncoder) IsStringable

func (me MapEncoder) IsStringable(v reflect.Value) bool

type MatchF

type MatchF func(a, b interface{}) bool

MatchF is an equality function protocol used by sets and cmaps.

type NilEncoder

type NilEncoder struct{}

func NewNilEncoder

func NewNilEncoder() *NilEncoder

func (NilEncoder) Encode

func (ie NilEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (NilEncoder) IsStringable

func (ie NilEncoder) IsStringable(v reflect.Value) bool

type NoopCache

type NoopCache struct{}

NoopCache is a do-nothing implementation of a cache.

func NewNoopCache

func NewNoopCache() *NoopCache

func (*NoopCache) IsCacheable

func (c *NoopCache) IsCacheable(s string, asKey bool) bool

func (*NoopCache) Write

func (c *NoopCache) Write(s string) string

type PointerEncoder

type PointerEncoder struct{}

func NewPointerEncoder

func NewPointerEncoder() *PointerEncoder

func (PointerEncoder) Encode

func (ie PointerEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (PointerEncoder) IsStringable

func (ie PointerEncoder) IsStringable(v reflect.Value) bool

type RollingCache

type RollingCache struct {
	// contains filtered or unexported fields
}

func NewRollingCache

func NewRollingCache() *RollingCache

func (*RollingCache) Clear

func (rc *RollingCache) Clear()

func (*RollingCache) HasKey

func (rc *RollingCache) HasKey(name string) bool

func (*RollingCache) IsCacheKey

func (rc *RollingCache) IsCacheKey(name string) bool

IsCacheKey returns true if the string looks like a cache key.

func (*RollingCache) IsCacheable

func (rc *RollingCache) IsCacheable(s string, asKey bool) bool

IsCacheable returns true if the string is long enough to be cached and either asKey is true or the string represents a symbol, keyword or tag.

func (*RollingCache) Read

func (rc *RollingCache) Read(name string) string

func (*RollingCache) String

func (rc *RollingCache) String() string

func (*RollingCache) Write

func (rc *RollingCache) Write(name string) string

Enter the name into the cache if it passes the cacheable critieria. Returns either the name or the value that was previously cached for the name.

type RuneEncoder

type RuneEncoder struct{}

func NewRuneEncoder

func NewRuneEncoder() *RuneEncoder

func (RuneEncoder) Encode

func (ie RuneEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (RuneEncoder) IsStringable

func (ie RuneEncoder) IsStringable(v reflect.Value) bool

type Set

type Set struct {
	Contents []interface{}
}

A set is a very simple minded representation of a set, one that does not enforce any redundancy constraints. Just a box for sets read from transit.

func MakeSet

func MakeSet(contents ...interface{}) *Set

func NewSet

func NewSet(contents []interface{}) *Set

func (Set) Contains

func (s Set) Contains(value interface{}, mf MatchF) bool

func (Set) ContainsEq

func (s Set) ContainsEq(value interface{}) bool

func (Set) String

func (s Set) String() string

type SetEncoder

type SetEncoder struct{}

func NewSetEncoder

func NewSetEncoder() *SetEncoder

func (SetEncoder) Encode

func (ie SetEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (SetEncoder) IsStringable

func (ie SetEncoder) IsStringable(v reflect.Value) bool

type StringEncoder

type StringEncoder struct{}

func NewStringEncoder

func NewStringEncoder() *StringEncoder

func (StringEncoder) Encode

func (ie StringEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (StringEncoder) IsStringable

func (ie StringEncoder) IsStringable(v reflect.Value) bool

type StringMap

type StringMap map[string]string

type Symbol

type Symbol string

A Symbol is a transit symbol, really just a string by another type.

type SymbolEncoder

type SymbolEncoder struct{}

func NewSymbolEncoder

func NewSymbolEncoder() *SymbolEncoder

func (SymbolEncoder) Encode

func (ie SymbolEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (SymbolEncoder) IsStringable

func (ie SymbolEncoder) IsStringable(v reflect.Value) bool

type TUri

type TUri struct {
	Value string
}

A TUri is just a container for a uri string. Go url.URL cannot handle all of the non-ascii chars of transit uris, hence the need for this type.

func NewTUri

func NewTUri(x string) *TUri

func (TUri) String

func (turi TUri) String() string

func (TUri) ToURL

func (turi TUri) ToURL() (*url.URL, error)

type TUriEncoder

type TUriEncoder struct{}

func NewTUriEncoder

func NewTUriEncoder() *TUriEncoder

func (TUriEncoder) Encode

func (ie TUriEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (TUriEncoder) IsStringable

func (ie TUriEncoder) IsStringable(v reflect.Value) bool

type TagId

type TagId string

A tag id represents a #tag in the transit protocol.

func (TagId) String

func (t TagId) String() string

type TaggedValue

type TaggedValue struct {
	Tag   TagId
	Value interface{}
}

type TaggedValueEncoder

type TaggedValueEncoder struct{}

func NewTaggedValueEncoder

func NewTaggedValueEncoder() *TaggedValueEncoder

func (TaggedValueEncoder) Encode

func (ie TaggedValueEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (TaggedValueEncoder) IsStringable

func (ie TaggedValueEncoder) IsStringable(v reflect.Value) bool

type TimeEncoder

type TimeEncoder struct{}

func NewTimeEncoder

func NewTimeEncoder() *TimeEncoder

func (TimeEncoder) Encode

func (ie TimeEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (TimeEncoder) IsStringable

func (ie TimeEncoder) IsStringable(v reflect.Value) bool

type TransitError

type TransitError struct {
	Message string      // Describe the error.
	Source  interface{} // The value that cause the problem.
}

func NewTransitError

func NewTransitError(msg string, v interface{}) *TransitError

func (*TransitError) Error

func (e *TransitError) Error() string

type UintEncoder

type UintEncoder struct{}

func NewUintEncoder

func NewUintEncoder() *UintEncoder

func (UintEncoder) Encode

func (ie UintEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (UintEncoder) IsStringable

func (ie UintEncoder) IsStringable(v reflect.Value) bool

type UrlEncoder

type UrlEncoder struct{}

func NewUrlEncoder

func NewUrlEncoder() *UrlEncoder

func (UrlEncoder) Encode

func (ie UrlEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (UrlEncoder) IsStringable

func (ie UrlEncoder) IsStringable(v reflect.Value) bool

type UuidEncoder

type UuidEncoder struct{}

func NewUuidEncoder

func NewUuidEncoder() *UuidEncoder

func (UuidEncoder) Encode

func (ie UuidEncoder) Encode(e Encoder, v reflect.Value, asKey bool) error

func (UuidEncoder) IsStringable

func (ie UuidEncoder) IsStringable(v reflect.Value) bool

type ValueEncoder

type ValueEncoder interface {
	IsStringable(reflect.Value) bool
	Encode(e Encoder, value reflect.Value, asString bool) error
}

ValueEncoder is the interface for objects that know how to transit encode a single value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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