packaged

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: GPL-3.0 Imports: 15 Imported by: 0

README

Packaged

Elegant and efficient Golang service management. Supports environment variable binding and service startup in a specified order.

Features
  • Service Management: Organize and manage service startup in a predefined order.
  • Environment Variable Binding: Automatically bind services with environment variables to ensure proper configuration.
  • Optimized for Efficiency: Focused on performance and simplicity.
  • This package is a pure Go implementation with no third-party or C dependencies.
Installation

To install this package, run the following command:

go get github.com/RealFax/packaged
Usage
  1. Setup Services: Define the services you want to manage using this package.
  2. Configure Environment Variables: Bind necessary environment variables to each service.
  3. Start Services: Use the package to start services in the required order.
Example:

see: https://github.com/RealFax/packaged/tree/main/example

License

This project is licensed under the GPL-3.0 License. See the LICENSE file for details.

Acknowledgments

Documentation

Index

Constants

View Source
const PublicNamespace = "__public_namespace__"

Variables

View Source
var (
	ErrQuitUnexpectedly = errors.New("quit unexpectedly")
)
View Source
var ServiceName string = "packaged-daemon"

Functions

func Register

func Register(newFc NewService, opts ...UnitOptions)

Register adds a new service to the internal service manager.

func Run

func Run() error

Run starts the internal service manager and launches all registered services.

func Stop

func Stop()

Stop gracefully stops all services managed by the internal service manager.

func Wait

func Wait()

Wait blocks execution until all services have completed or stopped.

Types

type Context

type Context struct {
	context.Context

	Namespace
	// contains filtered or unexported fields
}

func (*Context) Stop

func (c *Context) Stop()

type EnvManager

type EnvManager interface {
	GetEnv(key string) (string, bool)
	GetEnvInt(key string) (int, error)
	GetEnvFloat(key string) (float64, error)
	GetEnvBool(key string) (bool, error)
	GetEnvTime(key string, layout string) (time.Time, error)
	GetEnvDuration(key string) (time.Duration, error)
	Assign(dest any) error
}

type Kit

type Kit struct {
	context.Context

	Logger
	// contains filtered or unexported fields
}

func New

func New(opts ...KitOptions) *Kit

func (*Kit) Register

func (k *Kit) Register(newFc NewService, opts ...UnitOptions)

func (*Kit) Run

func (k *Kit) Run() error

func (*Kit) Stop

func (k *Kit) Stop()

func (*Kit) Wait

func (k *Kit) Wait()

type KitOptions

type KitOptions func(*Kit)

func WithLogger

func WithLogger(logger Logger) KitOptions

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
}

type Namespace

type Namespace interface {
	Name() string
	Set(key string, value any)
	Del(key string)
	Get(key string) (any, bool)
	Entries() []Service
	EnvManager
}

type NewService

type NewService func(ns Namespace) Service

type Restart

type Restart int32
const (
	RestartIgnore Restart = iota
	RestartAlways
	RestartRetry
)

type Service

type Service interface {
	Name() string
	Type() ServiceType
	OnInstall() error
	OnStart() error
	OnStop() error
	// contains filtered or unexported methods
}

type ServiceType

type ServiceType int32
const (
	ServiceTypeIgnore ServiceType = iota
	ServiceTypeBlocking
	ServiceTypeAsync
)

type UnimplementedHandler

type UnimplementedHandler struct{}

func (UnimplementedHandler) Name

func (h UnimplementedHandler) Name() string

func (UnimplementedHandler) OnInstall

func (h UnimplementedHandler) OnInstall() error

func (UnimplementedHandler) OnStart

func (h UnimplementedHandler) OnStart() error

func (UnimplementedHandler) OnStop

func (h UnimplementedHandler) OnStop() error

func (UnimplementedHandler) Type

type Unit

type Unit struct {
	Index, MaxRetry int32
	Namespace       string
	Description     string
	Entry           Service
	RestartPolicy   Restart
}

type UnitOptions

type UnitOptions func(*Unit)

func WithDescription

func WithDescription(desc string) UnitOptions

func WithIndex

func WithIndex(idx int32) UnitOptions

func WithMaxRetry

func WithMaxRetry(retry int32) UnitOptions

func WithNamespace

func WithNamespace(ns string) UnitOptions

func WithRestartPolicy

func WithRestartPolicy(rp Restart) UnitOptions

type Units

type Units []*Unit

func (Units) Sort

func (u Units) Sort(desc bool)

Directories

Path Synopsis
example
0-startup command

Jump to

Keyboard shortcuts

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