model

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2022 License: BSD-2-Clause Imports: 8 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertValueToType

func ConvertValueToType(value interface{}, targetType reflect.Type) (interface{}, error)

Types

type BrokerDestinationConfig

type BrokerDestinationConfig struct {
	Destination  string
	ConnectionId string
}

Used to specify the target user queue of the Response

type Direction

type Direction int

Direction int defining which way messages are travelling on a Channel.

const (
	RequestDir  Direction = 0
	ResponseDir Direction = 1
	ErrorDir    Direction = 2
)

type Message

type Message struct {
	Id            *uuid.UUID      `json:"id"`            // message identifier
	DestinationId *uuid.UUID      `json:"destinationId"` // destinationId (targeted recipient)
	Channel       string          `json:"channel"`       // reference to channel message was sent on.
	Destination   string          `json:"destination"`   // destination message was sent to (if galactic)
	Payload       interface{}     `json:"payload"`
	Error         error           `json:"error"`
	Direction     Direction       `json:"direction"`
	Headers       []MessageHeader `json:"headers"`
}

A Message is the encapsulation of the event sent on the bus. It holds a Direction, errors, a Payload and more.

func GenerateError

func GenerateError(msgConfig *MessageConfig) *Message

func GenerateRequest

func GenerateRequest(msgConfig *MessageConfig) *Message

func GenerateResponse

func GenerateResponse(msgConfig *MessageConfig) *Message

func (*Message) CastPayloadToType added in v1.3.3

func (m *Message) CastPayloadToType(typ interface{}) error

CastPayloadToType converts the raw interface{} typed Payload into the specified object passed as an argument.

type MessageConfig

type MessageConfig struct {
	Id            *uuid.UUID
	DestinationId *uuid.UUID
	Destination   string
	Channel       string
	Payload       interface{}
	Headers       []MessageHeader
	Direction     Direction
	Err           error
}

type MessageHeader

type MessageHeader struct {
	Label string
	Value string
}

A Message header can contain any meta data.

type Request

type Request struct {
	Id          *uuid.UUID  `json:"id"`
	Created     int64       `json:"created"`
	Version     int         `json:"version"`
	Destination string      `json:"channel"`
	Payload     interface{} `json:"payload"`
	Request     string      `json:"request"`
	// Populated if the request was sent on a "private" channel and
	// indicates where to send back the Response.
	// A service should check this field and if not null copy it to the
	// Response.BrokerDestination field to ensure that the response will be sent
	// back on the correct the "private" channel.
	BrokerDestination *BrokerDestinationConfig `json:"-"`
}

func CreateServiceRequest added in v1.3.2

func CreateServiceRequest(requestType string, body []byte) Request

CreateServiceRequest is a small utility function that takes request type and payload and returns a new model.Request instance populated with them

func CreateServiceRequestWithHttpRequest added in v1.3.2

func CreateServiceRequestWithHttpRequest(requestType string, r *http.Request) Request

CreateServiceRequestWithHttpRequest does the same as CreateServiceRequest, except the payload is a pointer to the Incoming http.Request, so you can essentially extract what ever you want from the incoming request within your service.

func CreateServiceRequestWithValues added in v1.3.2

func CreateServiceRequestWithValues(requestType string, vals url.Values) Request

CreateServiceRequestWithValues does the same as CreateServiceRequest, except the payload is url.Values and not A byte[] array

type Response

type Response struct {
	Id           *uuid.UUID  `json:"id"`
	Created      string      `json:"created"`
	Version      int         `json:"version"`
	Destination  string      `json:"channel"`
	Payload      interface{} `json:"payload"`
	Error        bool        `json:"error"`
	ErrorCode    int         `json:"errorCode"`
	ErrorMessage string      `json:"errorMessage"`
	// If populated the response will be send to a single client
	// on the specified destination topic.
	BrokerDestination *BrokerDestinationConfig `json:"-"`
	Headers           map[string]string        `json:"headers"` // passthrough any http stuff.
}

ResponseDir represents a payload sent by a Fabric application.

type ResponseHandlerFunction

type ResponseHandlerFunction func(*Response)

type StoreContentResponse

type StoreContentResponse struct {
	Items        map[string]interface{} `json:"items"`
	ResponseType string                 `json:"responseType"` // should be "storeContentResponse"
	StoreId      string                 `json:"storeId"`
	StoreVersion int64                  `json:"storeVersion"`
}

func NewStoreContentResponse

func NewStoreContentResponse(
	storeId string, items map[string]interface{}, storeVersion int64) *StoreContentResponse

type UpdateStoreResponse

type UpdateStoreResponse struct {
	ItemId       string      `json:"itemId"`
	NewItemValue interface{} `json:"newItemValue"`
	ResponseType string      `json:"responseType"` // should be "updateStoreResponse"
	StoreId      string      `json:"storeId"`
	StoreVersion int64       `json:"storeVersion"`
}

func NewUpdateStoreResponse

func NewUpdateStoreResponse(
	storeId string, itemId string, newValue interface{}, storeVersion int64) *UpdateStoreResponse

Jump to

Keyboard shortcuts

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