{"modulePath":"github.com/dockerstack/amazon-ecs-agent","version":"v1.2.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package wsclient\n\nPackage wsclient wraps the generated aws-sdk-go client to provide marshalling and unmarshalling of data over a websocket connection in the format expected by backend. It allows for bidirectional communication and acts as both a client-and-server in terms of requests, but only as a client in terms of connecting.\n\nPackage wsclient wraps the generated aws-sdk-go client to provide marshalling and unmarshalling of data over a websocket connection in the format expected by backend. It allows for bidirectional communication and acts as both a client-and-server in terms of requests, but only as a client in terms of connecting.\n\n## Constants\n\n```go\nconst (\n\t// ServiceName defines the service name for the agent. This is used to sign messages\n\t// that are sent to the backend.\n\tServiceName = \"ecs\"\n)\n```\n\n## Functions\n\n```go\nfunc DecodeConnectionError(data []byte, dec TypeDecoder) (interface{}, string, error)\n```\nDecodeConnectionError decodes some of the connection errors returned by the backend. Some differ from the usual ones in that they do not have a 'type' and 'message' field, but rather are of the form {\"ErrorType\":\"ErrorMessage\"}\n\n```go\nfunc DecodeData(data []byte, dec TypeDecoder) (interface{}, string, error)\n```\nDecodeData decodes a raw message into its type. E.g. An ACS message of the form {\"type\":\"FooMessage\",\"message\":{\"foo\":1}} will be decoded into the corresponding \\*ecsacs.FooMessage type. The type string, \"FooMessage\", will also be returned as a convenience.\n\n## Types\n\n```go\ntype ClientServer interface {\n\tAddRequestHandler(RequestHandler)\n\tMakeRequest(input interface{}) error\n\tConnect() error\n\tServe() error\n\tio.Closer\n}\n```\nClientServer is a combined client and server for the backend websocket connection\n\n```go\ntype ClientServerImpl struct {\n\tAcceptInvalidCert  bool\n\tConn               WebsocketConn\n\tCredentialProvider credentials.AWSCredentialProvider\n\tRegion             string\n\t// RequestHandlers is a map from message types to handler functions of the\n\t// form:\n\t//     \"FooMessage\": func(message *ecsacs.FooMessage)\n\tRequestHandlers map[string]RequestHandler\n\t// URL is the full url to the backend, including path, querystring, and so on.\n\tURL string\n\tClientServer\n\tServiceError\n\tTypeDecoder\n}\n```\nClientServerImpl wraps commonly used methods defined in ClientServer interface.\n\n```go\nfunc (cs *ClientServerImpl) AddRequestHandler(f RequestHandler)\n```\nAddRequestHandler adds a request handler to this client. A request handler \\*must\\* be a function taking a single argument, and that argument \\*must\\* be a pointer to a recognized 'ecsacs' struct. E.g. if you desired to handle messages from acs of type 'FooMessage', you would pass the following handler in:\n\n\tfunc(message *ecsacs.FooMessage)\n\nThis function will panic if the passed in function does not have one pointer argument or the argument is not a recognized type. Additionally, the request handler will block processing of further messages on this connection so it's important that it return quickly.\n\n```go\nfunc (cs *ClientServerImpl) Connect() error\n```\nConnect opens a connection to the backend and upgrades it to a websocket. Calls to 'MakeRequest' can be made after calling this, but responss will not be receivable until 'Serve' is also called.\n\n```go\nfunc (cs *ClientServerImpl) ConsumeMessages() error\n```\nConsumeMessages reads messages from the websocket connection and handles read messages from an active connection.\n\n```go\nfunc (cs *ClientServerImpl) CreateRequestMessage(input interface{}) ([]byte, error)\n```\nCreateRequestMessage creates the request json message using the given input. Note, the input \\*MUST\\* be a pointer to a valid backend type that this client recognises.\n\n```go\nfunc (cs *ClientServerImpl) MakeRequest(input interface{}) error\n```\nMakeRequest makes a request using the given input. Note, the input \\*MUST\\* be a pointer to a valid backend type that this client recognises\n\n```go\ntype NotMarshallableWSRequest struct {\n\tType string\n\n\tErr error\n}\n```\nNotMarshallableWSRequest represents that the given request input could not be marshalled\n\n```go\nfunc (u *NotMarshallableWSRequest) Error() string\n```\nError implements error\n\n```go\nfunc (u *NotMarshallableWSRequest) Retry() bool\n```\nRetry implementes Retriable\n\n```go\ntype ReceivedMessage struct {\n\tType    string          `json:\"type\"`\n\tMessage json.RawMessage `json:\"message\"`\n}\n```\nReceivedMessage is the intermediate message used to unmarshal a message from backend\n\n```go\ntype RequestHandler interface{}\n```\nRequestHandler would be func(\\*ecsacs.T for T in ecsacs.\\*) to be more proper, but it needs to be interface{} to properly capture that\n\n```go\ntype RequestMessage struct {\n\tType    string          `json:\"type\"`\n\tMessage json.RawMessage `json:\"message\"`\n}\n```\nRequestMessage is the intermediate message marshalled to send to backend.\n\n```go\ntype ServiceError interface {\n\tNewError(err interface{}) *WSError\n}\n```\nServiceError defines methods to return new backend specific error objects.\n\n```go\ntype TypeDecoder interface {\n\t// NewOfType returns an object of a recognized type for a given type name.\n\t// It additionally returns a boolean value which is set to false for an\n\t// unrecognized type.\n\tNewOfType(string) (interface{}, bool)\n\n\t// GetRecognizedTypes returns a map of type-strings (as passed in acs/tcs messages as\n\t// the 'type' field) to a pointer to the corresponding struct type this type should\n\t// be marshalled/unmarshalled to/from.\n\tGetRecognizedTypes() map[string]reflect.Type\n}\n```\nTypeDecoder interface defines methods to decode ecs types.\n\n```go\ntype UndecodableMessage struct {\n\tMsg string\n}\n```\nUndecodableMessage indicates that a message from the backend could not be decoded\n\n```go\nfunc (u *UndecodableMessage) Error() string\n```\n\n```go\ntype UnrecognizedWSRequestType struct {\n\tType string\n}\n```\nUnrecognizedWSRequestType specifies that a given type is not recognized. This error is not retriable.\n\n```go\nfunc (u *UnrecognizedWSRequestType) Error() string\n```\nError implements error\n\n```go\nfunc (u *UnrecognizedWSRequestType) Retry() bool\n```\nRetry implements Retriable\n\n```go\ntype WSError struct {\n\tErrObj interface{}\n\tType   string\n\tWSUnretriableErrors\n}\n```\nWSError wraps all the typed errors that the backend may return This will not be needed once the aws-sdk-go generation handles error types more cleanly\n\n```go\nfunc (err *WSError) Error() string\n```\nError returns an error string\n\n```go\nfunc (err *WSError) Retry() bool\n```\nRetry returns true if this error should be considered retriable\n\n```go\ntype WSUnretriableErrors interface {\n\tGet() []interface{}\n}\n```\nWSUnretriableErrors defines methods to retrieve the list of unretriable errors.\n\n```go\ntype WebsocketConn interface {\n\tWriteMessage(messageType int, data []byte) error\n\tReadMessage() (messageType int, data []byte, err error)\n\tClose() error\n}\n```\nWebsocketConn specifies the subset of gorilla/websocket's connection's methods that this client uses.\n\n","path":"github.com/dockerstack/amazon-ecs-agent/agent/wsclient","name":"wsclient","synopsis":"Package wsclient wraps the generated aws-sdk-go client to provide marshalling and unmarshalling of data over a websocket connection in the format expected by backend.","isRedistributable":true}
