Documentation ¶
Index ¶
- Constants
- type Client
- func (c *Client) Close() error
- func (c *Client) Do(req *Request) Result
- func (c *Client) DoMany(reqs []*Request) []Result
- func (c *Client) Events() <-chan *Event
- func (c *Client) Get(path, contentType string) ([]byte, error)
- func (c *Client) GetJSON(path string) ([]byte, error)
- func (c *Client) Name() string
- func (c *Client) Poke(app string, data json.RawMessage) Result
- func (c *Client) PokeShip(ship, app string, data json.RawMessage) Result
- func (c *Client) Scry(app, path string) ([]byte, error)
- func (c *Client) Subscribe(app, path string) Result
- func (c *Client) SubscribeShip(ship, app, path string) Result
- func (c *Client) Unsubscribe(subscriptionID uint64) Result
- type DialOptions
- type Event
- type Request
- type Result
Constants ¶
const ( ActionPoke = "poke" ActionSubscribe = "subscribe" ActionUnsubscribe = "unsubscribe" )
const ( // Special Type of Event used by Client to emit information // that doesn't come from the ship, e.g. errors Client had // processing data. ClientError = "go-client-error" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a connection with an Urbit ship.
func Dial ¶
func Dial(addr, code string, opts *DialOptions) (*Client, error)
Dial connects to an Urbit ship via HTTP address using code to authenticate. Returns a Client that can be used to perform further Requests.
func (*Client) DoMany ¶
DoMany combines multiple requests into a single HTTP request and send to the ship. Returns a Result for each request.
func (*Client) Events ¶
Events returns the channel used to obtain events coming from the ship.
The library doesn't buffer individual events coming from the ship, so it is important that the user code consume this channel, to make sure progress is made in all the different requests.
func (*Client) Get ¶
Get makes an HTTP GET request to the path inside the ship with a certain Content-Type.
func (*Client) GetJSON ¶
GetJSON makes an HTTP GET request to the path inside the ship with Content-Type set to "application/json".
func (*Client) Poke ¶
func (c *Client) Poke(app string, data json.RawMessage) Result
Poke sends a "poke" request to the ship Client is connected to.
func (*Client) PokeShip ¶
func (c *Client) PokeShip(ship, app string, data json.RawMessage) Result
PokeShip sends a "poke" request to a given ship.
func (*Client) Scry ¶
Scry makes a query to the ship state. Note that not all state "scry-able" via the ship is exported via HTTP.
func (*Client) Subscribe ¶
Subscribe to a given path of an app in the ship Client is connected to. If subscription succeeds, the ship will send (likely multiple) "diff" events containing updates.
func (*Client) SubscribeShip ¶
Subscribe to a given path of an app in the given ship. If subscription succeeds, the ship will send (likely multiple) "diff" events containing updates.
func (*Client) Unsubscribe ¶
Unsubscribe finishes a subscription.
type DialOptions ¶
type DialOptions struct { // Trace indicated whether the Client should print to Stderr // information about messages sent and received. Used mostly // for debugging. Trace bool // HTTPClient is used to set a custom HTTP client to be used // by the Client. HTTPClient *http.Client }
DialOptions include various options
type Event ¶
type Event struct { ID uint64 Type string `json:"response"` Ok *string Err *string Data json.RawMessage `json:"json"` }
Event represents an update sent from the ship to the Client.
type Request ¶
type Request struct { Action string `json:"action"` // Poke and Subscribe only. Ship string `json:"ship,omitempty"` App string `json:"app,omitempty"` // Subscribe only. Path string `json:"path,omitempty"` // Poke only. Mark string `json:"mark,omitempty"` Data json.RawMessage `json:"json,omitempty"` // Unsubscribe only. Subscription uint64 `json:"subscription,omitempty"` // contains filtered or unexported fields }
Request represents a request made from a client to a ship.
It is an "union" of the valid fields for all Action values, so some fields might be ignored, see inline comments below.
type Result ¶
type Result struct { // ID assigned to the request. Can be used to find associated // events when consuming the Events channel. ID uint64 // Err is not nil if the request resulted in an Error. Note // that even if the Request is succesfully sent, it is still // possible that Err become non-nil later. See also Wait. Err error // Requests with a single response will have a channel so can // be waited on with the final result. See also Wait. Response <-chan error }
Result is obtained after sending a request.