Exemplo n.º 1
0
// Dial connects to conduit and confirms the API capabilities for future calls.
func (d *Dialer) Dial(
	host string,
	options *core.ClientOptions,
) (*Conn, error) {
	var res responses.ConduitCapabilitiesResponse

	// We use conduit.connect for authentication and it establishes a session.
	err := core.PerformCall(
		core.GetEndpointURI(host, "conduit.getcapabilities"),
		nil,
		&res,
		options,
	)
	if err != nil {
		return nil, err
	}

	// Now, we need to assert that the conduit API supports this client.
	assertSupportedCapabilities(res, options)

	conn := Conn{
		host:         host,
		capabilities: &res,
		dialer:       d,
		options:      options,
	}

	return &conn, nil
}
Exemplo n.º 2
0
// Call allows you to make a raw conduit method call. Params will be marshalled
// as JSON and the result JSON will be unmarshalled into the result interface{}.
//
// This is primarily useful for calling conduit endpoints that aren't
// specifically supported by other methods in this package.
func (c *Conn) Call(
	method string,
	params interface{},
	result interface{},
) error {
	return core.PerformCall(
		core.GetEndpointURI(c.host, method),
		params,
		&result,
		c.options,
	)
}