Documentation

Index

Constants

This section is empty.

Variables

View Source
var Extensions []*Extension

Extensions that have been registered via Extend or otherwise.

Functions

func Config

func Config() map[string]interface{}

Config for global services (including Extensions). If there are multiple entries with the same identifier and non-empty config, they are excluded.

func Init

func Init(ctx context.Context, r *Registry) error

Init global services (including Extensions).

Types

type Extension

type Extension struct {
	Name   string      // Can be overridden to avoid conflicts.
	Config interface{} // Pointer to a custom struct type, or nil.
	Init   func(context.Context, *Registry) error
}

Extension declaration.

func Extend

func Extend(
	name string,
	config interface{},
	init func(context.Context, *Registry) error,
) *Extension

Extend Gate with configurable services. Name should be the extension package's identifier: if full the package name is example.net/foo, it should be foo.

type Factory

type Factory interface {
	Service() Service
	Discoverable(ctx context.Context) bool
	CreateInstance(ctx context.Context, config InstanceConfig, snapshot []byte) (Instance, error)
}

Factory creates instances of a particular service implementation.

See https://github.com/gate-computer/gate/blob/master/Service.md for service naming conventions.

type Instance

type Instance interface {
	Ready(ctx context.Context) error
	Start(ctx context.Context, send chan<- packet.Buf, abort func(error)) error
	Handle(ctx context.Context, send chan<- packet.Buf, received packet.Buf) error
	Shutdown(ctx context.Context) error
	Suspend(ctx context.Context) (snapshot []byte, err error)
}

Instance of a service. Corresponds to a program instance.

type InstanceBase

type InstanceBase struct{}

InstanceBase provides default implementations for some Instance methods.

func (InstanceBase) Ready

func (InstanceBase) Shutdown

func (InstanceBase) Shutdown(context.Context) error

func (InstanceBase) Start

func (InstanceBase) Start(context.Context, chan<- packet.Buf, func(error)) error

type InstanceConfig

type InstanceConfig struct {
	packet.Service
}

InstanceConfig for a service instance.

type Registry

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

Registry is a runtime.ServiceRegistry implementation. It multiplexes packets to service implementations.

func (*Registry) Catalog

func (r *Registry) Catalog(ctx context.Context) (services []Service)

Catalog of service metadata. Only the services which are discoverable in this context are included.

func (*Registry) Clone

func (r *Registry) Clone() *Registry

Clone the registry shallowly. The new registry may be used to add or replace services without affecting the original registry.

func (*Registry) MustRegister

func (r *Registry) MustRegister(f Factory)

MustRegister a service implementation. May replace an existing service. Panicks if service information is invalid.

func (*Registry) Register

func (r *Registry) Register(f Factory) error

Register a service implementation. Doesn't replace an existing service.

func (*Registry) StartServing

func (r *Registry) StartServing(ctx context.Context, serviceConfig runtime.ServiceConfig, initial []snapshot.Service, send chan<- packet.Buf, recv <-chan packet.Buf,
) (runtime.ServiceDiscoverer, []runtime.ServiceState, <-chan error, error)

StartServing implements the runtime.ServiceRegistry interface function.

type Service

type Service struct {
	Name     string `json:"name"`
	Revision string `json:"revision"`
}

Service metadata.

Directories

Path Synopsis
api