Documentation
¶
Overview ¶
Package document provides interface definitions and error types for document types.
A document is a protocol-agnostic type which supports a JSON-like data-model. You can use this type to send UTF-8 strings, arbitrary precision numbers, booleans, nulls, a list of these values, and a map of UTF-8 strings to these values.
API Clients expose document constructors in their respective client document packages which must be used to Marshal and Unmarshal Go types to and from their respective protocol representations.
See the Marshaler and Unmarshaler type documentation for more details on how to Go types can be converted to and from document types.
Index ¶
- func IsNoSerde(x interface{}) bool
- type Blob
- type Boolean
- type InvalidMarshalError
- type InvalidUnmarshalError
- type List
- type Map
- type Marshaler
- type NoSerde
- type Null
- type Number
- type Opaque
- type String
- type Structure
- type Timestamp
- type UnmarshalError
- type UnmarshalTypeError
- type Unmarshaler
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type InvalidMarshalError ¶
type InvalidMarshalError struct {
Message string
}
An InvalidMarshalError is an error type representing an error occurring when marshaling a Go value type.
func (*InvalidMarshalError) Error ¶
func (e *InvalidMarshalError) Error() string
Error returns the string representation of the error. Satisfying the error interface.
type InvalidUnmarshalError ¶
An InvalidUnmarshalError is an error type representing an invalid type encountered while unmarshaling a Smithy document to a Go value type.
func (*InvalidUnmarshalError) Error ¶
func (e *InvalidUnmarshalError) Error() string
Error returns the string representation of the error. Satisfying the error interface.
type Marshaler ¶
Marshaler is an interface for a type that marshals a document to its protocol-specific byte representation and returns the resulting bytes. A non-nil error will be returned if an error is encountered during marshaling.
Marshal supports basic scalars (int,uint,float,bool,string), big.Int, and big.Float, maps, slices, and structs. Anonymous nested types are flattened based on Go anonymous type visibility.
When defining struct types. the `document` struct tag can be used to control how the value will be marshaled into the resulting protocol document.
// Field is ignored Field int `document:"-"` // Field object of key "myName" Field int `document:"myName"` // Field object key of key "myName", and // Field is omitted if the field is a zero value for the type. Field int `document:"myName,omitempty"` // Field object key of "Field", and // Field is omitted if the field is a zero value for the type. Field int `document:",omitempty"`
All struct fields, including anonymous fields, are marshaled unless the any of the following conditions are meet.
- the field is not exported
- document field tag is "-"
- document field tag specifies "omitempty", and is a zero value.
Pointer and interface values are encoded as the value pointed to or contained in the interface. A nil value encodes as a null value unless `omitempty` struct tag is provided.
Channel, complex, and function values are not encoded and will be skipped when walking the value to be marshaled.
time.Time is not supported and will cause the Marshaler to return an error. These values should be represented by your application as a string or numerical representation.
Errors that occur when marshaling will stop the marshaler, and return the error.
Marshal cannot represent cyclic data structures and will not handle them. Passing cyclic structures to Marshal will result in an infinite recursion.
Marshaler is not used in schema-serde based services (which are currently being rolled out) since having an implementation of Marshaler locks a document into support for a specific serial format. Existing implementations of Marshaler will continue to encode to JSON as that is effectively the only serial format supported for Document prior to the introduction of schema-serde. In schema-serde services it is replaced by Value.