runtime

package
v0.1.19 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AdapterTypeCommand    = "command"
	AdapterTypeCapability = "capability"
	AdapterTypeProvider   = "provider"
)
View Source
const (
	CapabilityBootstrap      = "bootstrap"
	CapabilityBootstrapError = "bootstrap.error"
)
View Source
const (
	GroupAPI      = "api"
	GroupWorker   = "worker"
	GroupSystem   = "system"
	GroupInternal = "internal"
)
View Source
const (
	ScopeGlobal       = "global"
	ScopeServiceLocal = "service_local"
)
View Source
const DefaultStopTimeout = 10 * time.Second

Variables

View Source
var (
	ErrAdapterNil             = errors.New("runtime: adapter is nil")
	ErrAdapterNameRequired    = errors.New("runtime: adapter name is required")
	ErrAdapterTypeRequired    = errors.New("runtime: adapter type is required")
	ErrAdapterTypeUnsupported = errors.New("runtime: adapter type is unsupported")
	ErrAdapterNameDuplicate   = errors.New("runtime: adapter name is duplicate")
	ErrAdapterNotFound        = errors.New("runtime: adapter not found")
)
View Source
var (
	ErrCapabilityNil           = errors.New("runtime: capability is nil")
	ErrCapabilityNameRequired  = errors.New("runtime: capability name is required")
	ErrCapabilityNameReserved  = errors.New("runtime: capability name is reserved")
	ErrCapabilityNameDuplicate = errors.New("runtime: capability name is duplicate")
	ErrCapabilityNotFound      = errors.New("runtime: capability not found")
)
View Source
var (
	ErrCommandNil           = errors.New("runtime: command is nil")
	ErrCommandNameRequired  = errors.New("runtime: command name is required")
	ErrCommandNameReserved  = errors.New("runtime: command name is reserved")
	ErrCommandNameDuplicate = errors.New("runtime: command name is duplicate")
	ErrCommandNotFound      = errors.New("runtime: command not found")
)
View Source
var (
	ErrContainerNil         = errors.New("runtime: container is nil")
	ErrContainerKeyRequired = errors.New("runtime: container key is required")
	ErrContainerValueNil    = errors.New("runtime: container value is nil")
)
View Source
var (
	ErrDependencyNameRequired = errors.New("runtime: dependency name is required")
	ErrDependencyMissing      = errors.New("runtime: dependency is missing")
	ErrDependencyDuplicate    = errors.New("runtime: dependency is duplicate")
	ErrDependencyCycle        = errors.New("runtime: dependency cycle detected")
)
View Source
var (
	ErrPluginNil           = errors.New("runtime: plugin is nil")
	ErrPluginNameRequired  = errors.New("runtime: plugin name is required")
	ErrPluginNameReserved  = errors.New("runtime: plugin name is reserved")
	ErrPluginNameDuplicate = errors.New("runtime: plugin name is duplicate")
	ErrPluginNotFound      = errors.New("runtime: plugin not found")
)
View Source
var (
	ErrProviderNil           = errors.New("runtime: provider is nil")
	ErrProviderNameRequired  = errors.New("runtime: provider name is required")
	ErrProviderNameReserved  = errors.New("runtime: provider name is reserved")
	ErrProviderNameDuplicate = errors.New("runtime: provider name is duplicate")
	ErrProviderNotFound      = errors.New("runtime: provider not found")
	ErrProviderServiceExited = errors.New("runtime: service provider exited before runtime stopped")
)
View Source
var ErrAppNil = errors.New("runtime: app is nil")
View Source
var ErrRegistryNil = errors.New("runtime: registry is nil")
View Source
var ErrServiceSpecLoaderRequired = errors.New("runtime: service specs loader is required")

Functions

func Execute

func Execute(app *App, args []string) error

func ExecuteContext

func ExecuteContext(ctx context.Context, app *App, args []string) error

func LocalCapabilityAs

func LocalCapabilityAs[T any](registry *LocalCapabilityRegistry, name string) (T, bool)

func MergeCapabilities

func MergeCapabilities(values []string, extra []string) []string

func MergeCapabilitiesForService

func MergeCapabilitiesForService(serviceName string, values []string, extra []string) []string

func NotifySignals

func NotifySignals() (<-chan os.Signal, func())

func RegisterServiceProvider

func RegisterServiceProvider[T any](registry *ServiceRegistry[T], provider ServiceProvider[T]) error

func RunAllProviders

func RunAllProviders(ctx context.Context, app *App) error

func RunProvider

func RunProvider(ctx context.Context, app *App, name string) error

func ServiceRuntimeCapabilityNames added in v0.1.4

func ServiceRuntimeCapabilityNames(serviceName string, capabilities []CapabilityContract) []string

func StopOnSignal

func StopOnSignal(ctx context.Context, app *App, signals <-chan os.Signal) <-chan error

func ValidateDependencies

func ValidateDependencies(capabilities []Capability, providers []Provider) error

func WrapServiceConfigError

func WrapServiceConfigError(serviceName string, serviceType string, configKey string, err error) error

Types

type Adapter

type Adapter interface {
	AdapterMetadata() AdapterMetadata
}

type AdapterMetadata

type AdapterMetadata struct {
	Name     string
	Type     string
	Internal bool
}

type App

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

func New

func New() *App

func (*App) Adapter

func (a *App) Adapter(name string) (Adapter, bool)

func (*App) Adapters

func (a *App) Adapters() []Adapter

func (*App) AdaptersByType

func (a *App) AdaptersByType(adapterType string) []Adapter

func (*App) Capabilities

func (a *App) Capabilities() []Capability

func (*App) CapabilitiesByGroup

func (a *App) CapabilitiesByGroup(group string) []Capability

func (*App) CapabilitiesByScope

func (a *App) CapabilitiesByScope(scope string) []Capability

func (*App) Capability

func (a *App) Capability(name string) (Capability, bool)

func (*App) CapabilityStatus

func (a *App) CapabilityStatus(name string) Health

func (*App) CapabilityStatuses

func (a *App) CapabilityStatuses() []Health

func (*App) Command

func (a *App) Command(name string) (Command, bool)

func (*App) Commands

func (a *App) Commands() []Command

func (*App) CommandsByGroup

func (a *App) CommandsByGroup(group string) []Command

func (*App) Container

func (a *App) Container() *Container

func (*App) Context

func (a *App) Context() context.Context

func (*App) Dependencies

func (a *App) Dependencies() []DependencyMetadata

func (*App) Plugin

func (a *App) Plugin(name string) (Plugin, bool)

func (*App) Plugins

func (a *App) Plugins() []Plugin

func (*App) PluginsByGroup

func (a *App) PluginsByGroup(group string) []Plugin

func (*App) Provider

func (a *App) Provider(name string) (Provider, bool)

func (*App) ProviderStatus

func (a *App) ProviderStatus(name string) Health

func (*App) ProviderStatuses

func (a *App) ProviderStatuses() []Health

func (*App) Providers

func (a *App) Providers() []Provider

func (*App) ProvidersByGroup

func (a *App) ProvidersByGroup(group string) []Provider

func (*App) Register

func (a *App) Register(providers ...ProviderContract) error

func (*App) RegisterAdapters

func (a *App) RegisterAdapters(adapters ...Adapter) error

func (*App) RegisterCapabilities

func (a *App) RegisterCapabilities(capabilities ...CapabilityContract) error

func (*App) RegisterCommand

func (a *App) RegisterCommand(commands ...Command) error

func (*App) RegisterCommandAdapters

func (a *App) RegisterCommandAdapters(adapters ...CommandAdapter) error

func (*App) RegisterPlugins

func (a *App) RegisterPlugins(plugins ...Plugin) error

func (*App) RegisterProviderAdapters

func (a *App) RegisterProviderAdapters(adapters ...ProviderAdapter) error

func (*App) Run

func (a *App) Run(ctxs ...context.Context) error

func (*App) RunAllProviders

func (a *App) RunAllProviders(ctxs ...context.Context) error

func (*App) RunProvider

func (a *App) RunProvider(name string, ctxs ...context.Context) error

func (*App) Stop

func (a *App) Stop(ctx context.Context) error

func (*App) Use

func (a *App) Use(capabilities ...CapabilityContract) error

func (*App) UseCapabilityAdapters

func (a *App) UseCapabilityAdapters(adapters ...CapabilityAdapter) error

func (*App) ValidateDependencies

func (a *App) ValidateDependencies() error

type Capability

type Capability interface {
	CapabilityContract
	Status() Status
}

func NewCapability

func NewCapability(name string, register func(app *App) error) Capability

func NewCapabilityWithDependencies

func NewCapabilityWithDependencies(name string, dependencies []Dependency, register func(app *App) error, shutdown func(ctx context.Context) error) Capability

func NewCapabilityWithMetadata

func NewCapabilityWithMetadata(metadata CapabilityMetadata, register func(app *App) error, shutdown func(ctx context.Context) error) Capability

func NewCapabilityWithMetadataAndDependencies

func NewCapabilityWithMetadataAndDependencies(metadata CapabilityMetadata, dependencies []Dependency, register func(app *App) error, shutdown func(ctx context.Context) error) Capability

func NewCapabilityWithShutdown

func NewCapabilityWithShutdown(name string, register func(app *App) error, shutdown func(ctx context.Context) error) Capability

func SortCapabilities

func SortCapabilities(capabilities []Capability) ([]Capability, error)

type CapabilityAdapter

type CapabilityAdapter interface {
	Adapter
	Capability() CapabilityContract
}

func NewCapabilityAdapter

func NewCapabilityAdapter(metadata AdapterMetadata, capability CapabilityContract) CapabilityAdapter

type CapabilityContract

type CapabilityContract interface {
	Name() string
	Metadata() CapabilityMetadata
	Dependencies() []Dependency
	Register(app *App) error
	Shutdown(ctx context.Context) error
}

type CapabilityFunc

type CapabilityFunc func(app *App) error

func (CapabilityFunc) Dependencies

func (f CapabilityFunc) Dependencies() []Dependency

func (CapabilityFunc) Metadata

func (f CapabilityFunc) Metadata() CapabilityMetadata

func (CapabilityFunc) Name

func (f CapabilityFunc) Name() string

func (CapabilityFunc) Register

func (f CapabilityFunc) Register(app *App) error

func (CapabilityFunc) Shutdown

func (f CapabilityFunc) Shutdown(context.Context) error

func (CapabilityFunc) Status

func (f CapabilityFunc) Status() Status

type CapabilityMetadata

type CapabilityMetadata struct {
	Name        string
	Description string
	Group       string
	Scope       string
	Internal    bool
}

type Command

type Command interface {
	Name() string
	Metadata() CommandMetadata
	Run(ctx context.Context, app *App, args []string) error
}

func NewRunCommand added in v0.1.4

func NewRunCommand() Command

func NewServeCommand added in v0.1.4

func NewServeCommand() Command

type CommandAdapter

type CommandAdapter interface {
	Adapter
	Command() Command
}

func NewCommandAdapter

func NewCommandAdapter(metadata AdapterMetadata, command Command) CommandAdapter

type CommandMetadata

type CommandMetadata struct {
	Name        string
	Description string
	Group       string
	Internal    bool
}

type Container

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

func NewContainer

func NewContainer() *Container

func (*Container) Bind

func (c *Container) Bind(key Key, value any) error

func (*Container) Get

func (c *Container) Get(key Key) (any, bool)

func (*Container) MustGet

func (c *Container) MustGet(key Key) any

type Dependency

type Dependency struct {
	Name     string
	Required bool
}

func Optional

func Optional(name string) Dependency

func OptionalBootstrap added in v0.1.4

func OptionalBootstrap() Dependency

func OptionalCapabilities

func OptionalCapabilities(names ...string) []Dependency

func Require

func Require(name string) Dependency

func RequireBootstrap added in v0.1.4

func RequireBootstrap() Dependency

func RequireCapabilities

func RequireCapabilities(names ...string) []Dependency

type DependencyMetadata

type DependencyMetadata struct {
	Source   string
	Target   string
	Required bool
}

type HTTPService

type HTTPService struct {
	InfoValue ServiceInfo
	StartFunc func() error
	StopFunc  func(context.Context) error
}

func (HTTPService) ServiceInfo

func (s HTTPService) ServiceInfo() ServiceInfo

func (HTTPService) Shutdown

func (s HTTPService) Shutdown(ctx context.Context) error

func (HTTPService) Start

func (s HTTPService) Start(context.Context) error

type Health

type Health struct {
	Name   string
	Status Status
	Error  error
}

type Key

type Key string

type LocalCapability

type LocalCapability interface {
	Name() string
}

type LocalCapabilityRegistry

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

func NewLocalCapabilityRegistry

func NewLocalCapabilityRegistry() *LocalCapabilityRegistry

func (*LocalCapabilityRegistry) Add

func (r *LocalCapabilityRegistry) Add(capability LocalCapability)

func (*LocalCapabilityRegistry) AddName

func (r *LocalCapabilityRegistry) AddName(name string)

func (*LocalCapabilityRegistry) Close

func (r *LocalCapabilityRegistry) Close() error

func (*LocalCapabilityRegistry) Get

func (r *LocalCapabilityRegistry) Get(name string) (any, bool)

func (*LocalCapabilityRegistry) Names

func (r *LocalCapabilityRegistry) Names() []string

func (*LocalCapabilityRegistry) Set

func (r *LocalCapabilityRegistry) Set(name string, instance any)

type Plugin

type Plugin interface {
	Metadata() PluginMetadata
}

func NewPlugin

func NewPlugin(metadata PluginMetadata) Plugin

type PluginMetadata

type PluginMetadata struct {
	Name        string
	Description string
	Group       string
	Internal    bool
}

type Provider

type Provider interface {
	ProviderContract
	Status() Status
}

func SortProviders

func SortProviders(providers []Provider, capabilities []Capability) ([]Provider, error)

type ProviderAdapter

type ProviderAdapter interface {
	Adapter
	Provider() ProviderContract
}

func NewProviderAdapter

func NewProviderAdapter(metadata AdapterMetadata, provider ProviderContract) ProviderAdapter

type ProviderContract

type ProviderContract interface {
	Name() string
	Metadata() ProviderMetadata
	Dependencies() []Dependency
	Register(app *App) error
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
}

type ProviderMetadata

type ProviderMetadata struct {
	Name        string
	Description string
	Group       string
	Internal    bool
	Mode        ProviderMode
}

type ProviderMode

type ProviderMode string
const (
	ProviderModeService ProviderMode = "service"
	ProviderModeJob     ProviderMode = "job"
)

func ProviderModeOf

func ProviderModeOf(provider ProviderContract) ProviderMode

type Registry

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

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Adapter

func (r *Registry) Adapter(name string) (Adapter, bool)

func (*Registry) Adapters

func (r *Registry) Adapters() []Adapter

func (*Registry) AdaptersByType

func (r *Registry) AdaptersByType(adapterType string) []Adapter

func (*Registry) Capabilities

func (r *Registry) Capabilities() []Capability

func (*Registry) CapabilitiesByGroup

func (r *Registry) CapabilitiesByGroup(group string) []Capability

func (*Registry) CapabilitiesByScope

func (r *Registry) CapabilitiesByScope(scope string) []Capability

func (*Registry) Capability

func (r *Registry) Capability(name string) (Capability, bool)

func (*Registry) Command

func (r *Registry) Command(name string) (Command, bool)

func (*Registry) Commands

func (r *Registry) Commands() []Command

func (*Registry) CommandsByGroup

func (r *Registry) CommandsByGroup(group string) []Command

func (*Registry) Plugin

func (r *Registry) Plugin(name string) (Plugin, bool)

func (*Registry) Plugins

func (r *Registry) Plugins() []Plugin

func (*Registry) PluginsByGroup

func (r *Registry) PluginsByGroup(group string) []Plugin

func (*Registry) Provider

func (r *Registry) Provider(name string) (Provider, bool)

func (*Registry) Providers

func (r *Registry) Providers() []Provider

func (*Registry) ProvidersByGroup

func (r *Registry) ProvidersByGroup(group string) []Provider

func (*Registry) RegisterAdapters

func (r *Registry) RegisterAdapters(adapters ...Adapter) error

func (*Registry) RegisterCapabilities

func (r *Registry) RegisterCapabilities(capabilities ...CapabilityContract) error

func (*Registry) RegisterCommands

func (r *Registry) RegisterCommands(commands ...Command) error

func (*Registry) RegisterPlugins

func (r *Registry) RegisterPlugins(plugins ...Plugin) error

func (*Registry) RegisterProviders

func (r *Registry) RegisterProviders(providers ...ProviderContract) error

type RuntimeCapabilityContext

type RuntimeCapabilityContext[T any] struct {
	ConfigFile string
	Name       string
	Type       string
	ConfigKey  string
	Base       T
	// contains filtered or unexported fields
}

func NewRuntimeCapabilityContext

func NewRuntimeCapabilityContext[T any](configFile string, name string, serviceType string, configKey string, base T) RuntimeCapabilityContext[T]

func NewRuntimeCapabilityContextWithBaseLoader

func NewRuntimeCapabilityContextWithBaseLoader[T any](configFile string, name string, serviceType string, configKey string, baseLoader func() T) RuntimeCapabilityContext[T]

func (RuntimeCapabilityContext[T]) BaseConfig

func (ctx RuntimeCapabilityContext[T]) BaseConfig() T

func (RuntimeCapabilityContext[T]) LocalName

func (ctx RuntimeCapabilityContext[T]) LocalName(name string) string

type RuntimeCapabilityInfo

type RuntimeCapabilityInfo struct {
	Name     string
	Group    string
	Scope    string
	Internal bool
}

func RuntimeCapabilityInfoFor added in v0.1.4

func RuntimeCapabilityInfoFor(capability CapabilityContract) (RuntimeCapabilityInfo, bool)

func RuntimeCapabilityInfos added in v0.1.4

func RuntimeCapabilityInfos(app *App) []RuntimeCapabilityInfo

type RuntimeCapabilityProvider

type RuntimeCapabilityProvider interface {
	RuntimeCapabilities() []CapabilityContract
}

type Service

type Service interface {
	ServiceInfoProvider
	Start(context.Context) error
	Shutdown(context.Context) error
}

type ServiceApp

type ServiceApp[T any] struct {
	// contains filtered or unexported fields
}

func NewServiceApp

func NewServiceApp[T any](registry *ServiceRegistry[T]) *ServiceApp[T]

func (*ServiceApp[T]) Service

func (a *ServiceApp[T]) Service(serviceType string) *ServiceBuilder[T]

type ServiceBootstrap added in v0.1.4

type ServiceBootstrap[T any] struct {
	// contains filtered or unexported fields
}

func NewServiceBootstrap added in v0.1.4

func NewServiceBootstrap[T any](loadSpecs ServiceSpecLoader) *ServiceBootstrap[T]

func NewServiceBootstrapWithResolver added in v0.1.4

func NewServiceBootstrapWithResolver[T any](loadSpecs ServiceSpecLoader, resolveSpec ServiceSpecResolver) *ServiceBootstrap[T]

func (*ServiceBootstrap[T]) App added in v0.1.4

func (b *ServiceBootstrap[T]) App() *ServiceApp[T]

func (*ServiceBootstrap[T]) BuildService added in v0.1.4

func (b *ServiceBootstrap[T]) BuildService(configFile string, name string, serviceType string, base T) (Service, error)

func (*ServiceBootstrap[T]) BuildServiceWithCapabilities added in v0.1.4

func (b *ServiceBootstrap[T]) BuildServiceWithCapabilities(configFile string, name string, serviceType string, base T, capabilities *LocalCapabilityRegistry) (Service, error)

func (*ServiceBootstrap[T]) BuildServices added in v0.1.4

func (b *ServiceBootstrap[T]) BuildServices(configFile string, base T) ([]Service, error)

func (*ServiceBootstrap[T]) LoadServiceSpecs added in v0.1.4

func (b *ServiceBootstrap[T]) LoadServiceSpecs(configFile string) (map[string]ServiceSpec, error)

func (*ServiceBootstrap[T]) RegisterProvider added in v0.1.4

func (b *ServiceBootstrap[T]) RegisterProvider(provider ServiceProvider[T]) error

func (*ServiceBootstrap[T]) RegisterServiceDefinition added in v0.1.4

func (b *ServiceBootstrap[T]) RegisterServiceDefinition(def ServiceDefinition[T])

func (*ServiceBootstrap[T]) Registry added in v0.1.4

func (b *ServiceBootstrap[T]) Registry() *ServiceRegistry[T]

func (*ServiceBootstrap[T]) ResolveServiceConfigKey added in v0.1.4

func (b *ServiceBootstrap[T]) ResolveServiceConfigKey(configFile string, name string) (string, error)

func (*ServiceBootstrap[T]) ResolveServiceSpec added in v0.1.4

func (b *ServiceBootstrap[T]) ResolveServiceSpec(configFile string, name string) (ServiceSpec, error)

func (*ServiceBootstrap[T]) RuntimeCapabilitiesForService added in v0.1.4

func (b *ServiceBootstrap[T]) RuntimeCapabilitiesForService(ctx RuntimeCapabilityContext[T]) []CapabilityContract

func (*ServiceBootstrap[T]) Service added in v0.1.4

func (b *ServiceBootstrap[T]) Service(serviceType string) *ServiceBuilder[T]

func (*ServiceBootstrap[T]) ServiceDependenciesForType added in v0.1.4

func (b *ServiceBootstrap[T]) ServiceDependenciesForType(serviceType string) []Dependency

func (*ServiceBootstrap[T]) ServiceGroupForType added in v0.1.4

func (b *ServiceBootstrap[T]) ServiceGroupForType(serviceType string) string

func (*ServiceBootstrap[T]) ServiceKindForType added in v0.1.4

func (b *ServiceBootstrap[T]) ServiceKindForType(serviceType string) (ServiceKind, bool)

type ServiceBuilder

type ServiceBuilder[T any] struct {
	// contains filtered or unexported fields
}

func (*ServiceBuilder[T]) Dependencies added in v0.1.4

func (b *ServiceBuilder[T]) Dependencies(dependencies ...Dependency) *ServiceBuilder[T]

func (*ServiceBuilder[T]) Factory

func (b *ServiceBuilder[T]) Factory(factory ServiceFactory[T])

func (*ServiceBuilder[T]) FactoryContext

func (b *ServiceBuilder[T]) FactoryContext(factory ServiceContextFactory[T])

func (*ServiceBuilder[T]) Group added in v0.1.4

func (b *ServiceBuilder[T]) Group(group string) *ServiceBuilder[T]

func (*ServiceBuilder[T]) Kind

func (b *ServiceBuilder[T]) Kind(kind ServiceKind) *ServiceBuilder[T]

func (*ServiceBuilder[T]) OptionalCapabilities added in v0.1.4

func (b *ServiceBuilder[T]) OptionalCapabilities(names ...string) *ServiceBuilder[T]

func (*ServiceBuilder[T]) RequireCapabilities added in v0.1.4

func (b *ServiceBuilder[T]) RequireCapabilities(names ...string) *ServiceBuilder[T]

func (*ServiceBuilder[T]) RuntimeCapabilities

func (b *ServiceBuilder[T]) RuntimeCapabilities(factory ServiceRuntimeCapabilityFactory[T]) *ServiceBuilder[T]

type ServiceCapabilityProvider

type ServiceCapabilityProvider interface {
	Capabilities() []LocalCapability
}

type ServiceConfigError

type ServiceConfigError struct {
	ServiceName string
	ServiceType string
	ConfigKey   string
	Err         error
}

func (ServiceConfigError) Error

func (e ServiceConfigError) Error() string

func (ServiceConfigError) Unwrap

func (e ServiceConfigError) Unwrap() error

type ServiceContext

type ServiceContext[T any] struct {
	ConfigFile   string
	Name         string
	Type         string
	ConfigKey    string
	Base         T
	Capabilities *LocalCapabilityRegistry
}

func EnsureServiceContext

func EnsureServiceContext[T any](ctx *ServiceContext[T], name string, serviceType string, base T) *ServiceContext[T]

func NewServiceContext

func NewServiceContext[T any](name string, serviceType string, base T) *ServiceContext[T]

func (*ServiceContext[T]) CapabilityLocalFirst

func (ctx *ServiceContext[T]) CapabilityLocalFirst(name string) (any, bool)

func (*ServiceContext[T]) CloseCapabilities

func (ctx *ServiceContext[T]) CloseCapabilities() error

type ServiceContextFactory

type ServiceContextFactory[T any] func(ctx ServiceContext[T]) (Service, error)

type ServiceDefinition

type ServiceDefinition[T any] struct {
	Type                     string
	Kind                     ServiceKind
	Group                    string
	Dependencies             []Dependency
	Factory                  ServiceFactory[T]
	ContextFactory           ServiceContextFactory[T]
	RuntimeCapabilityFactory ServiceRuntimeCapabilityFactory[T]
}

type ServiceFactory

type ServiceFactory[T any] func(configFile string, name string, base T) (Service, error)

type ServiceInfo

type ServiceInfo struct {
	Name         string
	Type         string
	Kind         ServiceKind
	Addr         string
	Enabled      bool
	Capabilities []string
}

type ServiceInfoProvider

type ServiceInfoProvider interface {
	ServiceInfo() ServiceInfo
}

type ServiceKind

type ServiceKind string
const (
	ServiceKindHTTP  ServiceKind = "http"
	ServiceKindQueue ServiceKind = "queue"
	ServiceKindCLI   ServiceKind = "cli"
)

type ServiceProvider

type ServiceProvider[T any] interface {
	Register(app *ServiceApp[T]) error
}

type ServiceProviderFunc

type ServiceProviderFunc[T any] func(app *ServiceApp[T]) error

func (ServiceProviderFunc[T]) Register

func (fn ServiceProviderFunc[T]) Register(app *ServiceApp[T]) error

type ServiceRegistered added in v0.1.4

type ServiceRegistered[T any] struct {
	App          *App
	Base         T
	Service      Service
	ServiceInfo  ServiceInfo
	Capabilities []RuntimeCapabilityInfo
	Selection    ServiceSelectionItem
}

type ServiceRegistry

type ServiceRegistry[T any] struct {
	// contains filtered or unexported fields
}

func NewServiceRegistry

func NewServiceRegistry[T any]() *ServiceRegistry[T]

func (*ServiceRegistry[T]) BuildService

func (r *ServiceRegistry[T]) BuildService(configFile string, name string, serviceType string, configKey string, base T) (Service, error)

func (*ServiceRegistry[T]) BuildServiceWithCapabilities

func (r *ServiceRegistry[T]) BuildServiceWithCapabilities(configFile string, name string, serviceType string, configKey string, base T, capabilities *LocalCapabilityRegistry) (Service, error)

func (*ServiceRegistry[T]) BuildServices

func (r *ServiceRegistry[T]) BuildServices(configFile string, specs map[string]ServiceSpec, base T) ([]Service, error)

func (*ServiceRegistry[T]) RegisterServiceDefinition

func (r *ServiceRegistry[T]) RegisterServiceDefinition(def ServiceDefinition[T])

func (*ServiceRegistry[T]) RuntimeCapabilitiesForService

func (r *ServiceRegistry[T]) RuntimeCapabilitiesForService(ctx RuntimeCapabilityContext[T]) []CapabilityContract

func (*ServiceRegistry[T]) ServiceDependencies added in v0.1.4

func (r *ServiceRegistry[T]) ServiceDependencies(serviceType string) []Dependency

func (*ServiceRegistry[T]) ServiceGroup added in v0.1.4

func (r *ServiceRegistry[T]) ServiceGroup(serviceType string) string

func (*ServiceRegistry[T]) ServiceKind

func (r *ServiceRegistry[T]) ServiceKind(serviceType string) (ServiceKind, bool)

type ServiceRunOptions added in v0.1.4

type ServiceRunOptions struct {
	ConfigFile string
	Services   []string
}

type ServiceRunner added in v0.1.4

type ServiceRunner[T any] struct {
	// contains filtered or unexported fields
}

func NewServiceRunner added in v0.1.4

func NewServiceRunner[T any](options ServiceRunnerOptions[T]) *ServiceRunner[T]

func (*ServiceRunner[T]) Bootstrap added in v0.1.4

func (r *ServiceRunner[T]) Bootstrap() *ServiceBootstrap[T]

func (*ServiceRunner[T]) NewApp added in v0.1.4

func (r *ServiceRunner[T]) NewApp(options ServiceRunOptions) (*App, error)

func (*ServiceRunner[T]) RegisterProviders added in v0.1.4

func (r *ServiceRunner[T]) RegisterProviders(providers ...ServiceProvider[T]) error

func (*ServiceRunner[T]) ResolveServiceType added in v0.1.4

func (r *ServiceRunner[T]) ResolveServiceType(configFile string, name string) (string, error)

func (*ServiceRunner[T]) SelectServices added in v0.1.4

func (r *ServiceRunner[T]) SelectServices(options ServiceRunOptions) (ServiceSelection, error)

type ServiceRunnerOptions added in v0.1.4

type ServiceRunnerOptions[T any] struct {
	Bootstrap           *ServiceBootstrap[T]
	LoadSpecs           ServiceSpecLoader
	ResolveSpec         ServiceSpecResolver
	Providers           []ServiceProvider[T]
	Capabilities        func(ServiceSelection) []CapabilityContract
	BaseConfig          func() T
	Dependencies        func(ServiceSelectionItem) []Dependency
	Group               func(ServiceSelectionItem) string
	CapabilityRegistry  func(*App) *LocalCapabilityRegistry
	CapabilityInfos     func(*App) []RuntimeCapabilityInfo
	NormalizeType       func(string) string
	AllowService        func(ServiceSelectionItem) bool
	OnServiceRegistered func(ServiceRegistered[T])
}

type ServiceRuntimeCapabilityFactory

type ServiceRuntimeCapabilityFactory[T any] func(ctx RuntimeCapabilityContext[T]) []CapabilityContract

type ServiceSelection added in v0.1.4

type ServiceSelection struct {
	ConfigFile string
	Services   []ServiceSelectionItem
}

type ServiceSelectionItem added in v0.1.4

type ServiceSelectionItem struct {
	ConfigFile   string
	Name         string
	Type         string
	ConfigKey    string
	Kind         ServiceKind
	Group        string
	Dependencies []Dependency
	Spec         ServiceSpec
	Explicit     bool
}

type ServiceSpec

type ServiceSpec struct {
	Type      string `mapstructure:"type" yaml:"type"`
	Enabled   *bool  `mapstructure:"enabled" yaml:"enabled"`
	ConfigKey string `mapstructure:"config_key" yaml:"config_key"`
}

func (ServiceSpec) ResolveConfigKey

func (s ServiceSpec) ResolveConfigKey(name string) string

type ServiceSpecLoader added in v0.1.4

type ServiceSpecLoader func(configFile string) (map[string]ServiceSpec, error)

type ServiceSpecResolver added in v0.1.4

type ServiceSpecResolver func(configFile string, name string) (ServiceSpec, error)

type Status

type Status string
const (
	StatusBooting      Status = "booting"
	StatusRunning      Status = "running"
	StatusStopping     Status = "stopping"
	StatusShuttingDown Status = StatusStopping
	StatusStopped      Status = "stopped"
	StatusFailed       Status = "failed"
)

Jump to

Keyboard shortcuts

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