hosting

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BackgroundService

type BackgroundService interface {
	Execute(ctx context.Context) error
}

BackgroundService is a long-running service started in parallel.

type BackgroundServiceAdapter

type BackgroundServiceAdapter struct {
	Svc BackgroundService
}

BackgroundServiceAdapter wraps a BackgroundService as a HostedService.

func (*BackgroundServiceAdapter) Start

func (*BackgroundServiceAdapter) Stop

type Host

type Host struct {
	Container      *di.Container
	Server         *srv.Server
	HealthRegistry *health.Registry

	ShutdownTimeout time.Duration
	// contains filtered or unexported fields
}

Host manages the lifecycle of the application.

func (*Host) AddHostedService

func (h *Host) AddHostedService(svc HostedService)

func (*Host) OnStart

func (h *Host) OnStart(fn func())

func (*Host) OnStop

func (h *Host) OnStop(fn func())

func (*Host) Run

func (h *Host) Run(ctx context.Context) error

func (*Host) Shutdown

func (h *Host) Shutdown(_ context.Context) error

func (*Host) State

func (h *Host) State() HostState

type HostBuilder

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

HostBuilder provides a fluent API for constructing a Host.

func NewBuilder

func NewBuilder() *HostBuilder

NewBuilder creates a new HostBuilder.

func (*HostBuilder) AddHostedService

func (b *HostBuilder) AddHostedService(svc HostedService) *HostBuilder

func (*HostBuilder) AddService

func (b *HostBuilder) AddService(svc BackgroundService) *HostBuilder

func (*HostBuilder) Build

func (b *HostBuilder) Build() *Host

func (*HostBuilder) ConfigureServices

func (b *HostBuilder) ConfigureServices(fn func(*di.Builder)) *HostBuilder

func (*HostBuilder) ConfigureWeb

func (b *HostBuilder) ConfigureWeb(fn func(*srv.Server)) *HostBuilder

func (*HostBuilder) OnStart

func (b *HostBuilder) OnStart(fn func()) *HostBuilder

func (*HostBuilder) OnStop

func (b *HostBuilder) OnStop(fn func()) *HostBuilder

func (*HostBuilder) WithAddr

func (b *HostBuilder) WithAddr(addr string) *HostBuilder

func (*HostBuilder) WithHealthRegistry

func (b *HostBuilder) WithHealthRegistry(r *health.Registry) *HostBuilder

func (*HostBuilder) WithShutdownTimeout

func (b *HostBuilder) WithShutdownTimeout(d time.Duration) *HostBuilder

func (*HostBuilder) WithStartupTimeout

func (b *HostBuilder) WithStartupTimeout(d time.Duration) *HostBuilder

type HostState

type HostState int32

HostState represents the current lifecycle state of a Host.

const (
	// HostStarting indicates the host is starting hosted services.
	HostStarting HostState = iota
	// HostRunning indicates the host is fully running.
	HostRunning
	// HostStopping indicates the host is shutting down.
	HostStopping
	// HostStopped indicates the host has finished shutting down.
	HostStopped
)

func (HostState) String

func (s HostState) String() string

type HostedService

type HostedService interface {
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
}

HostedService is a managed lifecycle service with explicit Start/Stop.

Jump to

Keyboard shortcuts

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