service

package
v0.0.0-...-93e21f3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2024 License: BSD-3-Clause Imports: 12 Imported by: 2

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]any

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, r *Registry) error

Init global services (including Extensions).

Types

type Extension

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

Extension declaration.

func Extend

func Extend(name string, config any, init func(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) bool
	CreateInstance(ctx Context, config InstanceConfig, snapshot []byte) (Instance, error)
}

Factory creates instances of a particular service implementation.

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

type Instance

type Instance interface {
	Ready(ctx Context) error
	Start(ctx Context, send chan<- packet.Thunk, abort func(error)) error
	Handle(ctx Context, send chan<- packet.Thunk, received packet.Buf) (packet.Buf, error)
	Shutdown(ctx 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) Ready(Context) error

func (InstanceBase) Shutdown

func (InstanceBase) Shutdown(Context, bool) ([]byte, error)

func (InstanceBase) Start

func (InstanceBase) Start(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) []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, 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