varlink

package module
v0.0.0-...-10c7b0c Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2024 License: MIT Imports: 8 Imported by: 0

README

Image for: README ¶

Warning: this project has moved to GitHub.

A Go library for Varlink.

License

MIT

Documentation

Image for: Documentation ¶

Overview

Package varlink implements the Varlink protocol.

See https://varlink.org/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a Varlink client.

Client methods are safe to use from multiple goroutines.

func NewClient

func NewClient(conn net.Conn) *Client

NewClient creates a Varlink client from a net.Conn.

func (*Client) Close

func (c *Client) Close() error

Close closes the connection.

func (*Client) Do

func (c *Client) Do(method string, in, out interface{}) error

Do performs a Varlink call.

in is a Go value marshaled to a JSON object which contains the request parameters. Similarly, out will be populated with the reply parameters.

func (*Client) DoMore

func (c *Client) DoMore(method string, in interface{}) (*ClientCall, error)

DoMore is similar to Do, but indicates to the service that multiple replies are expected.

type ClientCall

type ClientCall struct {
	// contains filtered or unexported fields
}

ClientCall represents an in-progress Varlink method call.

func (*ClientCall) Next

func (cc *ClientCall) Next(out interface{}) error

Next waits for a reply.

If there are no more replies, io.EOF is returned.

type ClientError

type ClientError struct {
	Name       string
	Parameters json.RawMessage
}

ClientError is a Varlink error returned by a service to a Client.

func (*ClientError) Error

func (err *ClientError) Error() string

Error implements the error interface.

type Handler

type Handler interface {
	HandleVarlink(call *ServerCall, req *ServerRequest) error
}

A Handler processes Varlink requests.

type Server

type Server struct {
	Handler Handler
}

Server is a Varlink server.

The Handler field must be set to a Varlink request handler.

func NewServer

func NewServer() *Server

NewServer creates a new Varlink server.

func (*Server) Serve

func (srv *Server) Serve(ln net.Listener) error

Serve listens for connections.

type ServerCall

type ServerCall struct {
	// contains filtered or unexported fields
}

ServerCall represents an in-progress Varlink method call.

Handlers may call Reply any number of times, then they must end the call with CloseWithReply.

func (*ServerCall) CloseWithReply

func (call *ServerCall) CloseWithReply(parameters interface{}) error

CloseWithReply sends a final reply and closes the call.

No more replies may be sent.

func (*ServerCall) Reply

func (call *ServerCall) Reply(parameters interface{}) error

Reply sends a non-final reply.

This can only be used if ServerRequest.More is set to true.

type ServerError

type ServerError struct {
	Name       string
	Parameters interface{}
}

ServerError is an error to be sent to a Varlink client.

func (*ServerError) Error

func (err *ServerError) Error() string

Error implements the error interface.

type ServerRequest

type ServerRequest struct {
	Method     string          `json:"method"`
	Parameters json.RawMessage `json:"parameters"`
	Oneway     bool            `json:"oneway,omitempty"`
	More       bool            `json:"more,omitempty"`
	Upgrade    bool            `json:"upgrade,omitempty"`
}

ServerRequest is a request coming from a Varlink client.

Directories

Image for: Directories ¶
Path Synopsis
cmd
Package varlinkdef implements the Varlink interface definition format.
Package varlinkdef implements the Varlink interface definition format.