Documentation ¶
Index ¶
- Constants
- func RequestQueueName(name string) string
- func ResponseQueueName(name string) string
- type Client
- func (c *Client) Call(method string, params []interface{}, queue string) (interface{}, error)
- func (c *Client) CallWithRequest(request *Request, queue string) (interface{}, error)
- func (c *Client) DecodeResponse(response *Response) (interface{}, error)
- func (c *Client) Publish(payload *Request, queue string) error
- func (c *Client) PublishAndWait(payload *Request, queue string) (*Response, error)
- func (c *Client) SetupResponseQueue() error
- type CustomError
- type Error
- type ErrorResponse
- type Handler
- type HandlerFunc
- type MethodNotFoundError
- type ParseError
- type Request
- type Response
- type Server
- type WrappedError
Examples ¶
Constants ¶
const DEFAULT_EXCHANGE = ""
Variables ¶
This section is empty.
Functions ¶
func RequestQueueName ¶
func ResponseQueueName ¶
Types ¶
type Client ¶
type Client struct { UUID uuid.UUID Connection *amqp.Connection Channel *amqp.Channel ResponseQueue *amqp.Queue // contains filtered or unexported fields }
func NewBareClient ¶
func NewBareClient(uuid uuid.UUID) *Client
Creates a client with the given UUID and initializes its internal data structures. Does not setup connections or perform any network operations. You will almost always want to use NewClient.
func NewClient ¶
Create a client, connect it to the given AMQP server, and setup a queue to receive responses on.
Example ¶
client, err := NewClient("amqp://localhost") if err != nil { panic(err) } resp, err := client.Call("uppercase", []interface{}{"Hello world."}, "default") if err != nil { panic(err) } else { fmt.Printf("uppercase: %s\n", resp) }
Output:
func (*Client) Call ¶
Call a remote method over JSON-RPC and return its response. This will block the goroutine on which it is called.
func (*Client) CallWithRequest ¶
func (*Client) DecodeResponse ¶
Figure out what was in the response payload: was it a result, an error, or unknown?
func (*Client) Publish ¶
payload: JSON-RPC request payload to be sent
queue: Queue on which to send the request
func (*Client) PublishAndWait ¶
Publishes a request onto the given queue, then waits for a response to that message on the client's response queue.
func (*Client) SetupResponseQueue ¶
Declares the response queue and starts consuming (listening) deliveries from it. This is normally the final step in setting up a usable client.
Note that this spawns a separate goroutine for handling replies from deliveries, so it does not block the calling goroutine.
type CustomError ¶
type CustomError struct {
// contains filtered or unexported fields
}
func (*CustomError) Code ¶
func (err *CustomError) Code() int
func (*CustomError) Data ¶
func (err *CustomError) Data() interface{}
func (*CustomError) Error ¶
func (err *CustomError) Error() string
func (*CustomError) Message ¶
func (err *CustomError) Message() string
type ErrorResponse ¶
type ErrorResponse struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data"` }
Format of an error object within a response object.
func (*ErrorResponse) Error ¶
func (e *ErrorResponse) Error() string
type HandlerFunc ¶
Allows ordinary functions to fulfill the Handler interface. Used by the DrainFunc method.
func (HandlerFunc) Handle ¶
func (fn HandlerFunc) Handle(req *Request) (interface{}, error)
type MethodNotFoundError ¶
type MethodNotFoundError struct {
// contains filtered or unexported fields
}
func (*MethodNotFoundError) Code ¶
func (err *MethodNotFoundError) Code() int
func (*MethodNotFoundError) Error ¶
func (err *MethodNotFoundError) Error() string
func (*MethodNotFoundError) Message ¶
func (err *MethodNotFoundError) Message() string
type ParseError ¶
type ParseError struct{}
func (*ParseError) Code ¶
func (err *ParseError) Code() int
func (*ParseError) Data ¶
func (err *ParseError) Data() interface{}
func (*ParseError) Error ¶
func (err *ParseError) Error() string
func (*ParseError) Message ¶
func (err *ParseError) Message() string
type Response ¶
type Response struct { JsonRpc string `json:"jsonrpc"` Id string `json:"id"` Result interface{} `json:"result"` Error *ErrorResponse `json:"error"` }
type Server ¶
type Server struct { Connection *amqp.Connection // contains filtered or unexported fields }
func NewServer ¶
func NewServer() *Server
Initialize a new server with all the necessary internal data structures.
func (*Server) Connect ¶
Connect to an AMQP server. This should be called after initializing a server with NewServer and before calling Start.
type WrappedError ¶
type WrappedError struct {
// contains filtered or unexported fields
}
Wraps a normal Go error to provide methods fulfilling the Error interface for use in crafting error objects in a response.
func (*WrappedError) Code ¶
func (err *WrappedError) Code() int
func (*WrappedError) Data ¶
func (err *WrappedError) Data() interface{}
func (*WrappedError) Message ¶
func (err *WrappedError) Message() string