Documentation
¶
Overview ¶
Package proxy provides a proxy that allows clients, such as Magma, to communicate with the pcas infrastructure. Communication in JSON format.
Overview ¶
- Upon connection the client should write a Handshake.
- The client may then write Request objects to the proxy, one at a time.
- Upon receiving and processing a Request, the proxy will write a Response.
- The client should read the Response before writing the next Request.
Handshake ¶
The Handshake describes configuration options, and should be written by the client immediately upon connecting to the proxy. The Handshake is of the form:
{ "SendLengthPrefix": bool }
If SendLengthPrefix is true then the proxy writes JSON objects to the port as strings of the form
s\nt
where s is a string representation of an integer N, t is a string containing the JSON, and t has length N bytes. If bool is false then the proxy writes JSON objects to the port as strings of the form
t
as above, without the length prefix.
Request ¶
A Request describes a request from the client to the proxy:
{ "ID": ULID, "Timeout": Duration, "Endpoint": string, "Operation": string, "Arguments": Arguments }
All keys are optional.
- ID is a client-provided request ULID. This client can use this, if desired, to associate requests with responses.
- Timeout is a timeout duration for handling this request. If Timeout is not specified, or if the Duration is <= 0, then the request will not timeout.
- Endpoint names the endpoint for this requests.
- Operation names the operation on this given endpoint. It is an error for Operation to be set, but for Endpoint to be omitted.
- Arguments are operation-specific arguments for this request. It is an error for Arguments to be set, but for either Operation or Endpoint to be omitted.
Upon handling a Request, proxy will write a Response.
Response ¶
A Response describes a response from the proxy to a Request from the client:
{ "ID": ULID, "Endpoint": string, "Operation": string, "Result": Result, "Error": string }
Here:
- ID is the client-provided request ULID set on the Request. If the request ID was omitted from the Request, this will be omitted from the response.
- Endpoint is the endpoint named in the request. If the endpoint was omitted from the Request, or is equal to the empty string, this will be omitted from the response.
- Operation is the operation named in the request. If the operation was omitted from the Request, or is equal to the empty string, this will be omitted from the response.
- Result is the operation-specific result.
- Error is a string describing any error performing this operation.
Error is set only if the request failed; if Error is not set then the request succeeded. At most one of Result or Error will be set.
Duration ¶
A Duration is defined by the JSON:
integer|string
In the case where Duration is given by an integer, it gives the number of nanoseconds in the duration. In the case where Duration is given by a string, this will be converted to a time.Duration via time.ParseDuration.
ULID ¶
A ULID is defined by the JSON:
string
which must consist of exactly 26 characters taken from the alphabet:
0123456789ABCDEFGHJKMNPQRSTVWXYZ
A ULID is used to encode a bitbucket.org/pcastools/ulid.ULID.
Available endpoints ¶
The available endpoints can be obtained by submitting a Request with empty Endpoint (and hence empty Operation and Arguments). The Response will have Result of the form:
{ "Endpoints": [string, ..., string] }
where Endpoints is an array of all available endpoints.
Available operations ¶
The available operations can be obtained for a given endpoint can be obtained by submitting a Request with Endpoint set (and non-empty) and empty Operation (and hence empty Arguments). The Response will have Result of the form:
{ "Operations": [string, ..., string] }
where Operations is an array of all available operations for this endpoint.
Index ¶
- func FlagSets() []flag.Set
- func Run(ctx context.Context, l net.Listener, options ...Option) error
- type Config
- type CreationFunc
- type Description
- type Endpoint
- type Message
- func (m Message) Keys() []string
- func (m Message) OnlyKeys(k ...string) error
- func (m Message) RequireKeys(k ...string) error
- func (m Message) ToBool(key string) (bool, bool, error)
- func (m Message) ToBoolSlice(key string) ([]bool, bool, error)
- func (m Message) ToDuration(key string) (time.Duration, bool, error)
- func (m Message) ToFloat64(key string) (float64, bool, error)
- func (m Message) ToFloat64Slice(key string) ([]float64, bool, error)
- func (m Message) ToInt(key string) (int, bool, error)
- func (m Message) ToInt64(key string) (int64, bool, error)
- func (m Message) ToInt64Slice(key string) ([]int64, bool, error)
- func (m Message) ToIntSlice(key string) ([]int, bool, error)
- func (m Message) ToMessage(key string) (Message, bool, error)
- func (m Message) ToMessageSlice(key string) ([]Message, bool, error)
- func (m Message) ToString(key string) (string, bool, error)
- func (m Message) ToStringSlice(key string) ([]string, bool, error)
- func (m Message) ToULID(key string) (ulid.ULID, bool, error)
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type CreationFunc ¶ added in v0.0.27
CreationFunc is the creation function for an endpoint.
type Description ¶ added in v0.0.27
type Description struct { Name string // The name of the endpoint Operations []string // The supported operations Create CreationFunc // The creation function for the endpoint Flag flag.Flag // An optional flag FlagSet flag.Set // An optional flag.Set }
Description describes an endpoint
func (Description) Register ¶ added in v0.0.27
func (d Description) Register()
Register registers an endpoint handler.
type Endpoint ¶
type Endpoint interface { io.Closer // Handle handles requests for operation 'op' with arguments 'args'. Handle(ctx context.Context, op string, args Message, lg log.Interface) (Message, error) }
Endpoint is an endpoint.
type Message ¶ added in v0.0.27
type Message map[string]interface{}
Message is the unstructured message type.
func (Message) OnlyKeys ¶ added in v0.0.27
OnlyKeys asserts that only (a subset of) the given keys are set.
func (Message) RequireKeys ¶ added in v0.0.27
RequireKeys asserts that the given keys are set.
func (Message) ToBool ¶ added in v0.0.27
ToBool attempts to return the entry for the given key as a boolean. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
func (Message) ToBoolSlice ¶ added in v0.0.27
ToBoolSlice attempts to return the entry for the given key as a []bool. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
func (Message) ToDuration ¶ added in v0.0.27
ToDuration attempts to return the entry for the given key as a time.Duration. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
A Duration is defined by the JSON:
integer|string
In the case where Duration is given by an integer, it gives the number of nanoseconds in the duration. In the case where Duration is given by a string, this will be converted to a time.Duration via time.ParseDuration. See [time#ParseDuration] for details on the format.
func (Message) ToFloat64 ¶ added in v0.0.27
ToFloat64 attempts to return the entry for the given key as a float64. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
func (Message) ToFloat64Slice ¶ added in v0.0.27
ToFloat64Slice attempts to return the entry for the given key as a []float64. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
func (Message) ToInt ¶ added in v0.0.27
ToInt attempts to return the entry for the given key as an int. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
func (Message) ToInt64 ¶ added in v0.0.27
ToInt64 attempts to return the entry for the given key as an int64. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
func (Message) ToInt64Slice ¶ added in v0.0.27
ToInt64Slice attempts to return the entry for the given key as a []int64. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
func (Message) ToIntSlice ¶ added in v0.0.27
ToIntSlice attempts to return the entry for the given key as a []int. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
func (Message) ToMessage ¶ added in v0.0.27
ToMessage attempts to return the entry for the given key as a Message. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
func (Message) ToMessageSlice ¶ added in v0.0.27
ToMessageSlice attempts to return the entry for the given key as a []Message. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
func (Message) ToString ¶ added in v0.0.27
ToString attempts to return the entry for the given key as a string. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
func (Message) ToStringSlice ¶ added in v0.0.27
ToStringSlice attempts to return the entry for the given key as a []string. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion.
func (Message) ToULID ¶ added in v0.0.27
ToULID attempts to return the entry for the given key as a ulid.ULID. The second return value will be true if and only if the entry is set, regardless of any errors in type conversion. Any record will be validated before being returned.
A ULID is defined by the JSON:
string
which must consist of exactly 26 characters taken from the alphabet:
0123456789ABCDEFGHJKMNPQRSTVWXYZ
A ULID is used to encode a ulid.ULID: see bitbucket.org/pcastools/ulid.
Directories
¶
Path | Synopsis |
---|---|
cmd
|
|
Package fs is an endpoint for fsd.
|
Package fs is an endpoint for fsd. |
Package gob is an endpoint for encoding and decoding of mathematical objects.
|
Package gob is an endpoint for encoding and decoding of mathematical objects. |
internal
|
|
Package keyvalue is an abstract endpoint for key-value connections.
|
Package keyvalue is an abstract endpoint for key-value connections. |
Package kvdb is an endpoint for the kvdb key-value driver.
|
Package kvdb is an endpoint for the kvdb key-value driver. |
Package log is an endpoint for log messages.
|
Package log is an endpoint for log messages. |
Package metrics is an endpoint for collecting metrics data.
|
Package metrics is an endpoint for collecting metrics data. |
Package mongodb is an endpoint for the mongodb key-value driver.
|
Package mongodb is an endpoint for the mongodb key-value driver. |
Package mysql is an endpoint for the mysql key-value driver.
|
Package mysql is an endpoint for the mysql key-value driver. |
Package postgres is an endpoint for the postgres key-value driver.
|
Package postgres is an endpoint for the postgres key-value driver. |
Package queue is an endpoint for the pcas queue system.
|
Package queue is an endpoint for the pcas queue system. |
Package rangedb is an endpoint for rangedb.
|
Package rangedb is an endpoint for rangedb. |
Package sqlite is an endpoint for the SQLite key-value driver.
|
Package sqlite is an endpoint for the SQLite key-value driver. |
Package version is an endpoint for version information.
|
Package version is an endpoint for version information. |