service

package
v0.0.0-...-9ccd474 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2022 License: BSD-3-Clause Imports: 11 Imported by: 6

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 {
	Properties() Properties
	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.Thunk, abort func(error)) error
	Handle(ctx context.Context, send chan<- packet.Thunk, received packet.Buf) (packet.Buf, error)
	Shutdown(ctx context.Context, suspend bool) (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, bool) ([]byte, error)

func (InstanceBase) Start

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

type InstanceConfig

type InstanceConfig struct {
	packet.Service
}

InstanceConfig for a service instance.

type Properties

type Properties struct {
	Service
	Streams bool // Should Instance.Handle() receive flow and data packets?
}

Properties of a service implementation.

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

func (r *Registry) CreateServer(ctx context.Context, serviceConfig runtime.ServiceConfig, initial []snapshot.Service, send chan<- packet.Thunk) (runtime.InstanceServer, []runtime.ServiceState, <-chan error, error)

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.

type Service

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

Service metadata.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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