Documentation
¶
Index ¶
- Constants
- func ByteArrayAsString(es *encodeState)
- func NilMapEmpty(es *encodeState)
- func NilSliceEmpty(es *encodeState)
- func NoStringEscaping(es *encodeState)
- func RawByteSlices(es *encodeState)
- func UnixTimestamp(es *encodeState)
- func UnsortedMap(es *encodeState)
- type DurationFmt
- type Encoder
- type Instruction
- type MarshalerError
- type Option
- type UnsupportedTypeError
- type UnsupportedValueError
- type Writer
Constants ¶
const ( DurationString = iota DurationMinutes DurationSeconds DurationMilliseconds DurationMicroseconds DurationNanoseconds )
Duration formats.
Variables ¶
This section is empty.
Functions ¶
func ByteArrayAsString ¶
func ByteArrayAsString(es *encodeState)
ByteArrayAsString encodes byte arrays as raw JSON strings.
func NilMapEmpty ¶
func NilMapEmpty(es *encodeState)
NilMapEmpty encodes a nil Go map as an empty JSON object, rather than null.
func NilSliceEmpty ¶
func NilSliceEmpty(es *encodeState)
NilSliceEmpty encodes a nil Go slice as an empty JSON array, rather than null.
func NoStringEscaping ¶
func NoStringEscaping(es *encodeState)
NoStringEscaping disables string escaping.
func RawByteSlices ¶
func RawByteSlices(es *encodeState)
RawByteSlices disables the default behavior that encodes byte slices as base64-encoded strings.
func UnixTimestamp ¶
func UnixTimestamp(es *encodeState)
UnixTimestamp configures the encoder to encode time.Time value as Unix timestamps. This setting has precedence over any time layout.
Types ¶
type DurationFmt ¶
type DurationFmt int
DurationFmt represents the format used to encode a time.Duration.
func (DurationFmt) String ¶
func (df DurationFmt) String() string
String implements the fmt.Stringer interface.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder writes the JSON values of a specific type using a set of instructions compiled when the encoder is instantiated.
func NewEncoder ¶
NewEncoder returns a new encoder that can marshal the values of the given type. The Encoder can be explicitly initialized by calling its Compile method, otherwise the operation is done on first call to Marshal.
type Instruction ¶
Instruction represents a function that writes the JSON representation of a value to a stream.
type MarshalerError ¶
MarshalerError represents an error from calling a MarshalJSON or MarshalText method.
func (*MarshalerError) Error ¶
func (e *MarshalerError) Error() string
Error implements the builtin error interface.
type Option ¶
type Option func(*encodeState)
Option represents an option that defines the behavior of an encoder.
func DurationFormat ¶
func DurationFormat(df DurationFmt) Option
DurationFormat sets the format used to encode a time.Duration value.
func TimeLayout ¶
TimeLayout sets the time layout used to encode a time.Time value.
type UnsupportedTypeError ¶
UnsupportedTypeError is the error returned by an Encoder's Encode method when attempting to encode an unsupported value type.
func (*UnsupportedTypeError) Error ¶
func (e *UnsupportedTypeError) Error() string
Error implements the bultin error interface.
type UnsupportedValueError ¶
type UnsupportedValueError struct {
Str string
}
UnsupportedValueError is the error returned by an Encoder's Encode method when attempting to encode an unsupported value.
func (*UnsupportedValueError) Error ¶
func (e *UnsupportedValueError) Error() string
Error implements the builtin error interface.
type Writer ¶
type Writer interface {
io.Writer
io.StringWriter
io.ByteWriter
}
Writer is an interface that groups the io.Writer, io.StringWriter and io.ByteWriter interfaces.
