varlink

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2020 License: Apache-2.0 Imports: 13 Imported by: 16

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

View Source
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.

View Source
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

func (c *Call) GetParameters(p interface{}) error

GetParameters retrieves the method call parameters.

func (*Call) IsOneway

func (c *Call) IsOneway() bool

IsOneway indicate that the calling client does not expect a reply.

func (*Call) Reply

func (c *Call) Reply(ctx context.Context, parameters interface{}) error

Reply sends a reply to this method call.

func (*Call) ReplyError

func (c *Call) ReplyError(ctx context.Context, name string, parameters interface{}) error

ReplyError sends an error reply to this method call.

func (*Call) ReplyInterfaceNotFound

func (c *Call) ReplyInterfaceNotFound(ctx context.Context, interfaceA string) error

ReplyInterfaceNotFound sends a org.varlink.service error reply to this method call

func (*Call) ReplyInvalidParameter

func (c *Call) ReplyInvalidParameter(ctx context.Context, parameter string) error

ReplyInvalidParameter sends a org.varlink.service error reply to this method call

func (*Call) ReplyMethodNotFound

func (c *Call) ReplyMethodNotFound(ctx context.Context, method string) error

ReplyMethodNotFound sends a org.varlink.service error reply to this method call

func (*Call) ReplyMethodNotImplemented

func (c *Call) ReplyMethodNotImplemented(ctx context.Context, method string) error

ReplyMethodNotImplemented sends a org.varlink.service error reply to this method call

func (*Call) WantsMore

func (c *Call) WantsMore() bool

WantsMore indicates if the calling client accepts more than one reply to this method call.

func (*Call) WantsUpgrade

func (c *Call) WantsUpgrade() bool

WantsUpgrade indicates that the calling client wants the connection to be upgraded.

type Connection

type Connection struct {
	io.Closer
	// contains filtered or unexported fields
}

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) Close

func (c *Connection) Close() error

Close terminates the connection.

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

func (c *Connection) GetInterfaceDescription(ctx context.Context, name string) (string, error)

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

func (e *Error) DispatchError() error

func (*Error) Error

func (e *Error) Error() string

Error returns the fully-qualified varlink error name.

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) Close

func (p PipeCon) Close() error

func (PipeCon) LocalAddr added in v0.4.0

func (p PipeCon) LocalAddr() net.Addr

func (PipeCon) Read added in v0.4.0

func (p PipeCon) Read(b []byte) (n int, err error)

func (PipeCon) RemoteAddr added in v0.4.0

func (p PipeCon) RemoteAddr() net.Addr

func (PipeCon) SetDeadline added in v0.4.0

func (p PipeCon) SetDeadline(t time.Time) error

func (PipeCon) SetReadDeadline added in v0.4.0

func (p PipeCon) SetReadDeadline(t time.Time) error

func (PipeCon) SetWriteDeadline added in v0.4.0

func (p PipeCon) SetWriteDeadline(t time.Time) error

func (PipeCon) Write added in v0.4.0

func (p PipeCon) Write(b []byte) (n int, err error)

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

func NewResolver(ctx context.Context, address string) (*Resolver, error)

NewResolver returns a new resolver connected to the given address.

func (*Resolver) Close

func (r *Resolver) Close() error

Close terminates the resolver.

func (*Resolver) GetInfo

func (r *Resolver) GetInfo(ctx context.Context, vendor *string, product *string, version *string, url *string, interfaces *[]string) error

GetInfo requests information about the resolver.

func (*Resolver) Resolve

func (r *Resolver) Resolve(ctx context.Context, iface string) (string, error)

Resolve resolves a varlink interface name to a varlink 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

func NewService(vendor string, product string, version string, url string) (*Service, error)

NewService creates a new Service which implements the list of given varlink interfaces.

func (*Service) Bind

func (s *Service) Bind(ctx context.Context, address string) error

Bind binds the service to an address.

func (*Service) DoListen

func (s *Service) DoListen(ctx context.Context, timeout time.Duration) error

DoListen starts a Service.

func (*Service) GetListener

func (s *Service) GetListener() (net.Listener, error)

func (*Service) HandleMessage

func (s *Service) HandleMessage(ctx context.Context, conn ReadWriterContext, request []byte) error

func (*Service) Listen

func (s *Service) Listen(ctx context.Context, address string, timeout time.Duration) error

Listen starts a Service.

func (*Service) RegisterInterface

func (s *Service) RegisterInterface(iface dispatcher) error

RegisterInterface registers a varlink.Interface containing struct to the Service

func (*Service) Shutdown

func (s *Service) Shutdown() error

Shutdown shuts down the listener of a running service.

type ServiceTimeoutError

type ServiceTimeoutError struct{}

ServiceTimeoutError helps API users to special-case timeouts.

func (ServiceTimeoutError) Error

func (ServiceTimeoutError) Error() string

Directories

Path Synopsis
Package idl provides a varlink interface description parser.
Package idl provides a varlink interface description parser.
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL