Documentation
¶
Overview ¶
Package shapes is generated from shapes.yaml, which covers the schema forms the chat example does not: unions without a discriminator keyword, primitive variants, typed maps, nullable fields, recursive schemas and numeric enums.
Index ¶
- Constants
- func Dispatch(ctx context.Context, handler Handler, message ReceivedMessage) error
- func FeedAddress(typeValue, userID string) string
- type Batch
- func (v Batch) AsArrayOfString() ([]string, error)
- func (v Batch) AsMapOfInt64() (map[string]int64, error)
- func (v *Batch) FromArrayOfString(value []string) error
- func (v *Batch) FromMapOfInt64(value map[string]int64) error
- func (v Batch) MarshalJSON() ([]byte, error)
- func (v *Batch) UnmarshalJSON(data []byte) error
- func (v Batch) Validate() error
- func (v Batch) Value() (any, error)
- type Client
- type FramePayload
- func (v FramePayload) AsStartedFrame() (StartedFrame, error)
- func (v FramePayload) AsStoppedFrame() (StoppedFrame, error)
- func (v FramePayload) Discriminator() (string, error)
- func (v *FramePayload) FromStartedFrame(value StartedFrame) error
- func (v *FramePayload) FromStoppedFrame(value StoppedFrame) error
- func (v FramePayload) MarshalJSON() ([]byte, error)
- func (v *FramePayload) UnmarshalJSON(data []byte) error
- func (v FramePayload) Validate() error
- func (v FramePayload) Value() (any, error)
- type Handler
- type Level
- type Measurement
- func (v Measurement) AsFloat64() (float64, error)
- func (v Measurement) AsPoint() (Point, error)
- func (v Measurement) AsString() (string, error)
- func (v *Measurement) FromFloat64(value float64) error
- func (v *Measurement) FromPoint(value Point) error
- func (v *Measurement) FromString(value string) error
- func (v Measurement) MarshalJSON() ([]byte, error)
- func (v *Measurement) UnmarshalJSON(data []byte) error
- func (v Measurement) Validate() error
- func (v Measurement) Value() (any, error)
- type Node
- type Point
- type ReceivedMessage
- type SensorA
- type SensorB
- type SensorC
- type SensorReading
- type SensorReadingSource
- func (v SensorReadingSource) AsSensorA() (SensorA, error)
- func (v SensorReadingSource) AsSensorB() (SensorB, error)
- func (v SensorReadingSource) AsSensorC() (SensorC, error)
- func (v SensorReadingSource) Discriminator() (string, error)
- func (v *SensorReadingSource) FromSensorA(value SensorA) error
- func (v *SensorReadingSource) FromSensorB(value SensorB) error
- func (v *SensorReadingSource) FromSensorC(value SensorC) error
- func (v SensorReadingSource) MarshalJSON() ([]byte, error)
- func (v *SensorReadingSource) UnmarshalJSON(data []byte) error
- func (v SensorReadingSource) Validate() error
- func (v SensorReadingSource) Value() (any, error)
- type StartedFrame
- type StoppedFrame
- type Tags
- type UnimplementedHandler
- func (UnimplementedHandler) HandleFrame(context.Context, FramePayload) error
- func (UnimplementedHandler) HandleReading(context.Context, SensorReading) error
- func (UnimplementedHandler) HandleTree(context.Context, Node) error
- func (UnimplementedHandler) HandleUnknownMessage(ctx context.Context, data []byte, err error) error
Constants ¶
const ( // Payload: Node. MessageTree = "Tree" // An OpenAPI 3.0 schema, which brings nullable, boolean exclusive bounds and discriminator mappings. // Payload: SensorReading. MessageReading = "Reading" // Socket frames tagged by a const type, with no discriminator keyword. // Payload: FramePayload. MessageFrame = "Frame" )
Message names, as the spec gives them.
const FeedAddressTemplate = "feed/{type}/{userId}"
FeedAddressTemplate is the address of the Feed channel with its parameters unfilled.
Variables ¶
This section is empty.
Functions ¶
func Dispatch ¶
func Dispatch(ctx context.Context, handler Handler, message ReceivedMessage) error
Dispatch passes message to the handler method for its name.
func FeedAddress ¶
FeedAddress returns the address of the Feed channel with its parameters filled in.
Types ¶
type Batch ¶
type Batch struct {
// contains filtered or unexported fields
}
Batch holds one of several shapes. Set it with the From methods and read it with Value or the As methods.
func (Batch) AsArrayOfString ¶
AsArrayOfString decodes the held value as a []string.
func (Batch) AsMapOfInt64 ¶
AsMapOfInt64 decodes the held value as a map[string]int64.
func (*Batch) FromArrayOfString ¶
FromArrayOfString sets the held value to a []string.
func (*Batch) FromMapOfInt64 ¶
FromMapOfInt64 sets the held value to a map[string]int64.
func (Batch) MarshalJSON ¶
MarshalJSON encodes the held value.
func (*Batch) UnmarshalJSON ¶
UnmarshalJSON stores data after checking that it is exactly one variant.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client sends and receives this API's messages over a transport.
func NewClient ¶
func NewClient(transport asyncapirt.Transport) *Client
NewClient returns a client that uses transport.
func (*Client) PublishTree ¶
PublishTree validates payload and sends it as a MessageTree message.
type FramePayload ¶
type FramePayload struct {
// contains filtered or unexported fields
}
FramePayload holds one of several shapes. Set it with the From methods and read it with Value or the As methods.
func (FramePayload) AsStartedFrame ¶
func (v FramePayload) AsStartedFrame() (StartedFrame, error)
AsStartedFrame decodes the held value as a StartedFrame.
func (FramePayload) AsStoppedFrame ¶
func (v FramePayload) AsStoppedFrame() (StoppedFrame, error)
AsStoppedFrame decodes the held value as a StoppedFrame.
func (FramePayload) Discriminator ¶
func (v FramePayload) Discriminator() (string, error)
Discriminator returns the "type" property that selects the variant.
func (*FramePayload) FromStartedFrame ¶
func (v *FramePayload) FromStartedFrame(value StartedFrame) error
FromStartedFrame sets the held value to a StartedFrame.
func (*FramePayload) FromStoppedFrame ¶
func (v *FramePayload) FromStoppedFrame(value StoppedFrame) error
FromStoppedFrame sets the held value to a StoppedFrame.
func (FramePayload) MarshalJSON ¶
func (v FramePayload) MarshalJSON() ([]byte, error)
MarshalJSON encodes the held value.
func (*FramePayload) UnmarshalJSON ¶
func (v *FramePayload) UnmarshalJSON(data []byte) error
UnmarshalJSON stores data after checking that it is exactly one variant.
func (FramePayload) Validate ¶
func (v FramePayload) Validate() error
Validate checks that the held value is a valid variant.
func (FramePayload) Value ¶
func (v FramePayload) Value() (any, error)
Value decodes the held value as the variant its discriminator selects.
type Handler ¶
type Handler interface {
// Payload: Node.
HandleTree(ctx context.Context, payload Node) error
// An OpenAPI 3.0 schema, which brings nullable, boolean exclusive bounds and discriminator mappings.
// Payload: SensorReading.
HandleReading(ctx context.Context, payload SensorReading) error
// Socket frames tagged by a const type, with no discriminator keyword.
// Payload: FramePayload.
HandleFrame(ctx context.Context, payload FramePayload) error
// HandleUnknownMessage gets every message that matched nothing, with the
// reason. Returning an error stops Client.Run.
HandleUnknownMessage(ctx context.Context, data []byte, err error) error
}
Handler receives incoming messages. Embed UnimplementedHandler to implement only the methods you need.
type Measurement ¶
type Measurement struct {
// contains filtered or unexported fields
}
Measurement holds one of several shapes. Set it with the From methods and read it with Value or the As methods.
func (Measurement) AsFloat64 ¶
func (v Measurement) AsFloat64() (float64, error)
AsFloat64 decodes the held value as a float64.
func (Measurement) AsPoint ¶
func (v Measurement) AsPoint() (Point, error)
AsPoint decodes the held value as a Point.
func (Measurement) AsString ¶
func (v Measurement) AsString() (string, error)
AsString decodes the held value as a string.
func (*Measurement) FromFloat64 ¶
func (v *Measurement) FromFloat64(value float64) error
FromFloat64 sets the held value to a float64.
func (*Measurement) FromPoint ¶
func (v *Measurement) FromPoint(value Point) error
FromPoint sets the held value to a Point.
func (*Measurement) FromString ¶
func (v *Measurement) FromString(value string) error
FromString sets the held value to a string.
func (Measurement) MarshalJSON ¶
func (v Measurement) MarshalJSON() ([]byte, error)
MarshalJSON encodes the held value.
func (*Measurement) UnmarshalJSON ¶
func (v *Measurement) UnmarshalJSON(data []byte) error
UnmarshalJSON stores data after checking that it is exactly one variant.
func (Measurement) Validate ¶
func (v Measurement) Validate() error
Validate checks that the held value is a valid variant.
func (Measurement) Value ¶
func (v Measurement) Value() (any, error)
Value decodes the held value as the one variant it matches. The union has no discriminator, so every variant is tried and exactly one must decode.
type Node ¶
func (*Node) UnmarshalJSON ¶
UnmarshalJSON decodes Node strictly. Required properties must be present and the decoded value must pass Validate.
type Point ¶
func (*Point) UnmarshalJSON ¶
UnmarshalJSON decodes Point strictly. Required properties must be present and the decoded value must pass Validate. Properties the schema does not declare are rejected.
type ReceivedMessage ¶
ReceivedMessage is a decoded incoming message. Payload holds the payload type of the message Name names.
func DecodeReceivedMessage ¶
func DecodeReceivedMessage(data []byte) (ReceivedMessage, error)
DecodeReceivedMessage works out which incoming message data is and decodes it. It fails with asyncapirt.ErrUnknownMessage when nothing matches and asyncapirt.ErrAmbiguousMessage when several messages match.
type SensorA ¶
func (*SensorA) UnmarshalJSON ¶
UnmarshalJSON decodes SensorA strictly. Required properties must be present and the decoded value must pass Validate.
type SensorB ¶
func (*SensorB) UnmarshalJSON ¶
UnmarshalJSON decodes SensorB strictly. Required properties must be present and the decoded value must pass Validate.
type SensorC ¶
Not in the mapping and no const, so its schema name selects it.
func (*SensorC) UnmarshalJSON ¶
UnmarshalJSON decodes SensorC strictly. Required properties must be present and the decoded value must pass Validate.
type SensorReading ¶
type SensorReading struct {
Value Measurement `json:"value"`
Unit *string `json:"unit"`
Tags Tags `json:"tags"`
Level Level `json:"level"`
Ratio float32 `json:"ratio"`
Labels map[string]int32 `json:"labels"`
Range *string `json:"range,omitempty"`
Extra json.RawMessage `json:"extra,omitempty"`
Func *bool `json:"func,omitempty"`
Batch *Batch `json:"batch,omitempty"`
Source *SensorReadingSource `json:"source,omitempty"`
}
func (*SensorReading) UnmarshalJSON ¶
func (v *SensorReading) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes SensorReading strictly. Required properties must be present and the decoded value must pass Validate.
func (SensorReading) Validate ¶
func (v SensorReading) Validate() error
Validate checks the constraints the schema declares for SensorReading.
type SensorReadingSource ¶
type SensorReadingSource struct {
// contains filtered or unexported fields
}
SensorReadingSource holds one of several shapes. Set it with the From methods and read it with Value or the As methods.
func (SensorReadingSource) AsSensorA ¶
func (v SensorReadingSource) AsSensorA() (SensorA, error)
AsSensorA decodes the held value as a SensorA.
func (SensorReadingSource) AsSensorB ¶
func (v SensorReadingSource) AsSensorB() (SensorB, error)
AsSensorB decodes the held value as a SensorB.
func (SensorReadingSource) AsSensorC ¶
func (v SensorReadingSource) AsSensorC() (SensorC, error)
AsSensorC decodes the held value as a SensorC.
func (SensorReadingSource) Discriminator ¶
func (v SensorReadingSource) Discriminator() (string, error)
Discriminator returns the "kind" property that selects the variant.
func (*SensorReadingSource) FromSensorA ¶
func (v *SensorReadingSource) FromSensorA(value SensorA) error
FromSensorA sets the held value to a SensorA.
func (*SensorReadingSource) FromSensorB ¶
func (v *SensorReadingSource) FromSensorB(value SensorB) error
FromSensorB sets the held value to a SensorB.
func (*SensorReadingSource) FromSensorC ¶
func (v *SensorReadingSource) FromSensorC(value SensorC) error
FromSensorC sets the held value to a SensorC.
func (SensorReadingSource) MarshalJSON ¶
func (v SensorReadingSource) MarshalJSON() ([]byte, error)
MarshalJSON encodes the held value.
func (*SensorReadingSource) UnmarshalJSON ¶
func (v *SensorReadingSource) UnmarshalJSON(data []byte) error
UnmarshalJSON stores data after checking that it is exactly one variant.
func (SensorReadingSource) Validate ¶
func (v SensorReadingSource) Validate() error
Validate checks that the held value is a valid variant.
func (SensorReadingSource) Value ¶
func (v SensorReadingSource) Value() (any, error)
Value decodes the held value as the variant its discriminator selects.
type StartedFrame ¶
func (StartedFrame) MarshalJSON ¶
func (v StartedFrame) MarshalJSON() ([]byte, error)
MarshalJSON encodes StartedFrame with its const properties filled in.
func (*StartedFrame) UnmarshalJSON ¶
func (v *StartedFrame) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes StartedFrame strictly. Required properties must be present and the decoded value must pass Validate.
func (StartedFrame) Validate ¶
func (v StartedFrame) Validate() error
Validate checks the constraints the schema declares for StartedFrame.
type StoppedFrame ¶
type StoppedFrame struct {
Type string `json:"type"`
Sequence int64 `json:"sequence"`
Reason *string `json:"reason,omitempty"`
}
func (StoppedFrame) MarshalJSON ¶
func (v StoppedFrame) MarshalJSON() ([]byte, error)
MarshalJSON encodes StoppedFrame with its const properties filled in.
func (*StoppedFrame) UnmarshalJSON ¶
func (v *StoppedFrame) UnmarshalJSON(data []byte) error
UnmarshalJSON decodes StoppedFrame strictly. Required properties must be present and the decoded value must pass Validate.
func (StoppedFrame) Validate ¶
func (v StoppedFrame) Validate() error
Validate checks the constraints the schema declares for StoppedFrame.
type UnimplementedHandler ¶
type UnimplementedHandler struct{}
UnimplementedHandler ignores every message. Its HandleUnknownMessage logs a warning and keeps the receive loop running.
func (UnimplementedHandler) HandleFrame ¶
func (UnimplementedHandler) HandleFrame(context.Context, FramePayload) error
HandleFrame ignores the message.
func (UnimplementedHandler) HandleReading ¶
func (UnimplementedHandler) HandleReading(context.Context, SensorReading) error
HandleReading ignores the message.
func (UnimplementedHandler) HandleTree ¶
func (UnimplementedHandler) HandleTree(context.Context, Node) error
HandleTree ignores the message.
func (UnimplementedHandler) HandleUnknownMessage ¶
HandleUnknownMessage logs the message size and the reason, then continues.