Documentation ¶
Overview ¶
Package varlink provides varlink client and server implementations. See http://varlink.org for more information about varlink.
Example varlink interface definition in a org.example.this.varlink file:
interface org.example.this method Ping(in: string) -> (out: string)
Generated Go module in a orgexamplethis/orgexamplethis.go file. The generated module provides reply methods for all methods specified in the varlink interface description. The stub implementations return a MethodNotImplemented error; the service implementation using this module will override the methods with its own implementation.
// Generated with github.com/varlink/go/cmd/varlink-go-interface-generator package orgexamplethis import "github.com/varlink/go/varlink" type orgexamplethisInterface interface { Ping(c VarlinkCall, in string) error } type VarlinkCall struct{ varlink.Call } func (c *VarlinkCall) ReplyPing(out string) error { var out struct { Out string `json:"out,omitempty"` } out.Out = out return c.Reply(&out) } func (s *VarlinkInterface) Ping(c VarlinkCall, in string) error { return c.ReplyMethodNotImplemented("Ping") } [...]
Service implementing the interface and its method:
import ("orgexamplethis") type Data struct { orgexamplethis.VarlinkInterface data string } data := Data{data: "test"} func (d *Data) Ping(call orgexamplethis.VarlinkCall, ping string) error { return call.ReplyPing(ping) } service, _ = varlink.NewService( "Example", "This", "1", "https://example.org/this", ) service.RegisterInterface(orgexamplethis.VarlinkNew(&data)) err := service.Listen("unix:/run/org.example.this", 0)
Index ¶
- Constants
- type Call
- func (c *Call) GetParameters(p interface{}) error
- func (c *Call) IsOneway() bool
- func (c *Call) Reply(ctx context.Context, parameters interface{}) error
- func (c *Call) ReplyError(ctx context.Context, name string, parameters interface{}) error
- func (c *Call) ReplyInterfaceNotFound(ctx context.Context, interfaceA string) error
- func (c *Call) ReplyInvalidParameter(ctx context.Context, parameter string) error
- func (c *Call) ReplyMethodNotFound(ctx context.Context, method string) error
- func (c *Call) ReplyMethodNotImplemented(ctx context.Context, method string) error
- func (c *Call) WantsMore() bool
- func (c *Call) WantsUpgrade() bool
- type Connection
- func (c *Connection) Call(ctx context.Context, method string, parameters interface{}, ...) error
- func (c *Connection) Close() error
- func (c *Connection) GetInfo(ctx context.Context, vendor *string, product *string, version *string, ...) error
- func (c *Connection) GetInterfaceDescription(ctx context.Context, name string) (string, error)
- func (c *Connection) Send(ctx context.Context, method string, parameters interface{}, flags uint64) (func(context.Context, interface{}) (uint64, error), error)
- func (c *Connection) Upgrade(ctx context.Context, method string, parameters interface{}) (func(context.Context, interface{}) (uint64, ReadWriterContext, error), error)
- type Error
- type InterfaceNotFound
- type InvalidParameter
- type MethodNotFound
- type MethodNotImplemented
- type PipeCon
- func (p PipeCon) Close() error
- func (p PipeCon) LocalAddr() net.Addr
- func (p PipeCon) Read(b []byte) (n int, err error)
- func (p PipeCon) RemoteAddr() net.Addr
- func (p PipeCon) SetDeadline(t time.Time) error
- func (p PipeCon) SetReadDeadline(t time.Time) error
- func (p PipeCon) SetWriteDeadline(t time.Time) error
- func (p PipeCon) Write(b []byte) (n int, err error)
- type ReadWriterContext
- type Resolver
- type Service
- func (s *Service) Bind(ctx context.Context, address string) error
- func (s *Service) DoListen(ctx context.Context, timeout time.Duration) error
- func (s *Service) GetListener() (net.Listener, error)
- func (s *Service) HandleMessage(ctx context.Context, conn ReadWriterContext, request []byte) error
- func (s *Service) Listen(ctx context.Context, address string, timeout time.Duration) error
- func (s *Service) RegisterInterface(iface dispatcher) error
- func (s *Service) Shutdown() error
- type ServiceTimeoutError
Constants ¶
const ( More = 1 << iota Oneway = 1 << iota Continues = 1 << iota Upgrade = 1 << iota )
Message flags for Send(). More indicates that the client accepts more than one method reply to this call. Oneway requests, that the service must not send a method reply to this call. Continues indicates that the service will send more than one reply.
const ResolverAddress = "unix:/run/org.varlink.resolver"
ResolverAddress is the well-known address of the varlink interface resolver, it translates varlink interface names to varlink service addresses.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Call ¶
type Call struct { Conn ReadWriterContext Request *[]byte In *serviceCall Continues bool Upgrade bool }
Call is a method call retrieved by a Service. The connection from the client can be terminated by returning an error from the call instead of sending a reply or error reply.
func (*Call) GetParameters ¶
GetParameters retrieves the method call parameters.
func (*Call) ReplyError ¶
ReplyError sends an error reply to this method call.
func (*Call) ReplyInterfaceNotFound ¶
ReplyInterfaceNotFound sends a org.varlink.service error reply to this method call
func (*Call) ReplyInvalidParameter ¶
ReplyInvalidParameter sends a org.varlink.service error reply to this method call
func (*Call) ReplyMethodNotFound ¶
ReplyMethodNotFound sends a org.varlink.service error reply to this method call
func (*Call) ReplyMethodNotImplemented ¶
ReplyMethodNotImplemented sends a org.varlink.service error reply to this method call
func (*Call) WantsMore ¶
WantsMore indicates if the calling client accepts more than one reply to this method call.
func (*Call) WantsUpgrade ¶
WantsUpgrade indicates that the calling client wants the connection to be upgraded.
type Connection ¶
Connection is a connection from a client to a service.
func NewBridge ¶
func NewBridge(bridge string) (*Connection, error)
NewBridge returns a new connection with the given bridge.
func NewBridgeWithStderr ¶
func NewBridgeWithStderr(bridge string, stderr io.Writer) (*Connection, error)
NewBridgeWithStderr returns a new connection with the given bridge.
func NewConnection ¶
func NewConnection(ctx context.Context, address string) (*Connection, error)
NewConnection returns a new connection to the given address. The context is used when dialling. Once successfully connected, any expiration of the context will not affect the connection.
func (*Connection) Call ¶
func (c *Connection) Call(ctx context.Context, method string, parameters interface{}, outParameters interface{}) error
Call sends a method call and returns the method reply.
func (*Connection) GetInfo ¶
func (c *Connection) GetInfo(ctx context.Context, vendor *string, product *string, version *string, url *string, interfaces *[]string) error
GetInfo requests information about the service.
func (*Connection) GetInterfaceDescription ¶
GetInterfaceDescription requests the interface description string from the service.
func (*Connection) Send ¶
func (c *Connection) Send(ctx context.Context, method string, parameters interface{}, flags uint64) (func(context.Context, interface{}) (uint64, error), error)
Send sends a method call. It returns a receive() function which is called to retrieve the method reply. If Send() is called with the `More` flag and the receive() function carries the `Continues` flag, receive() can be called multiple times to retrieve multiple replies.
func (*Connection) Upgrade ¶ added in v0.3.0
func (c *Connection) Upgrade(ctx context.Context, method string, parameters interface{}) (func(context.Context, interface{}) (uint64, ReadWriterContext, error), error)
Upgrade attempts to upgrade the connection using the provided method and parameters. If successful, the connection cannot be reused later, and must be closed.
type Error ¶
type Error struct { Name string Parameters interface{} }
Error is a varlink error returned from a method call.
func (*Error) DispatchError ¶
type InterfaceNotFound ¶
type InterfaceNotFound struct {
Interface string `json:"interface"`
}
The requested interface was not found.
func (InterfaceNotFound) Error ¶
func (e InterfaceNotFound) Error() string
type InvalidParameter ¶
type InvalidParameter struct {
Parameter string `json:"parameter"`
}
One of the passed parameters is invalid.
func (InvalidParameter) Error ¶
func (e InvalidParameter) Error() string
type MethodNotFound ¶
type MethodNotFound struct {
Method string `json:"method"`
}
The requested method was not found
func (MethodNotFound) Error ¶
func (e MethodNotFound) Error() string
type MethodNotImplemented ¶
type MethodNotImplemented struct {
Method string `json:"method"`
}
The interface defines the requested method, but the service does not implement it.
func (MethodNotImplemented) Error ¶
func (e MethodNotImplemented) Error() string
type PipeCon ¶
type PipeCon struct {
// contains filtered or unexported fields
}
func (PipeCon) RemoteAddr ¶ added in v0.4.0
func (PipeCon) SetReadDeadline ¶ added in v0.4.0
func (PipeCon) SetWriteDeadline ¶ added in v0.4.0
type ReadWriterContext ¶ added in v0.3.0
type ReadWriterContext interface { Write(context.Context, []byte) (int, error) Read(context.Context, []byte) (int, error) ReadBytes(ctx context.Context, delim byte) ([]byte, error) }
ReadWriterContext describes the capabilities of the underlying varlink connection.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver resolves varlink interface names to varlink addresses
func NewResolver ¶
NewResolver returns a new resolver connected to the given address.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents an active varlink service. In addition to the registered custom varlink Interfaces, every service implements the org.varlink.service interface which allows clients to retrieve information about the running service.
func NewService ¶
NewService creates a new Service which implements the list of given varlink interfaces.
func (*Service) HandleMessage ¶
func (*Service) RegisterInterface ¶
RegisterInterface registers a varlink.Interface containing struct to the Service
type ServiceTimeoutError ¶
type ServiceTimeoutError struct{}
ServiceTimeoutError helps API users to special-case timeouts.
func (ServiceTimeoutError) Error ¶
func (ServiceTimeoutError) Error() string