modular

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2025 License: MIT Imports: 10 Imported by: 17

README

modular

Modular Go

Go Reference

Overview

Modular is a package that provides a way to create modular applications in Go. It allows you to create modules that can be easily added or removed from the application. It also provides a way to manage dependencies between modules.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigFeeders = []Feeder{
	feeders.EnvFeeder{},
}

Functions

This section is empty.

Types

type AppRegistry

type AppRegistry interface {
	SvcRegistry() ServiceRegistry
}

type Application

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

Application represents the core Application container

func NewApplication

func NewApplication(cp ConfigProvider, logger Logger) *Application

NewApplication creates a new application instance

func (*Application) ConfigProvider

func (app *Application) ConfigProvider() ConfigProvider

ConfigProvider retrieves the application config provider

func (*Application) GetConfigSection

func (app *Application) GetConfigSection(section string) (ConfigProvider, error)

GetConfigSection retrieves a configuration section

func (*Application) GetService

func (app *Application) GetService(name string, target any) error

GetService retrieves a service with type assertion

func (*Application) Init

func (app *Application) Init() error

Init initializes the application with the provided modules

func (*Application) Logger

func (app *Application) Logger() Logger

Logger represents a logger

func (*Application) RegisterConfigSection

func (app *Application) RegisterConfigSection(section string, cp ConfigProvider)

RegisterConfigSection registers a configuration section with the application

func (*Application) RegisterModule

func (app *Application) RegisterModule(module Module)

RegisterModule adds a module to the application

func (*Application) RegisterService

func (app *Application) RegisterService(name string, service any) error

RegisterService adds a service with type checking

func (*Application) Run

func (app *Application) Run() error

Run starts the application and blocks until termination

func (*Application) Start

func (app *Application) Start() error

Start starts the application

func (*Application) Stop

func (app *Application) Stop() error

Stop stops the application

func (*Application) SvcRegistry

func (app *Application) SvcRegistry() ServiceRegistry

SvcRegistry retrieves the service svcRegistry

type ComplexFeeder

type ComplexFeeder interface {
	Feeder
	FeedKey(string, interface{}) error
}

type Config

type Config struct {
	*config.Config
	StructKeys map[string]interface{}
}

func NewConfig

func NewConfig() *Config

func (*Config) AddStructKey

func (c *Config) AddStructKey(key string, target interface{}) *Config

func (*Config) Feed

func (c *Config) Feed() error

type ConfigProvider

type ConfigProvider interface {
	GetConfig() any
}

type Feeder

type Feeder = config.Feeder

Feeder aliases

type Logger

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

type Module

type Module interface {
	// RegisterConfig registers configuration requirements
	RegisterConfig(app *Application)

	// Init Initialize the module with the application context
	Init(app *Application) error

	// Start starts the module (non-blocking)
	Start(ctx context.Context) error

	// Stop gracefully stops the module
	Stop(ctx context.Context) error

	// Name returns the unique identifier for this module
	Name() string

	// Dependencies returns names of other modules this module depends on
	Dependencies() []string

	// ProvidesServices returns a list of services provided by this module
	ProvidesServices() []Service

	// RequiresServices returns a list of services required by this module
	RequiresServices() []ServiceDependency
}

Module represents a registrable component in the application

type ModuleConstructor

type ModuleConstructor func(app *Application, services map[string]any) (Module, error)

type ModuleRegistry

type ModuleRegistry map[string]Module

ModuleRegistry represents a svcRegistry of modules

type ModuleWithConstructor

type ModuleWithConstructor interface {
	Module
	Constructor() ModuleConstructor
}

type Service

type Service struct {
	Name        string
	Description string
	Instance    any
}

Service defines a service with metadata

type ServiceDependency

type ServiceDependency struct {
	Name               string
	Required           bool
	Type               reflect.Type // Concrete type (if known)
	SatisfiesInterface reflect.Type // Interface type (if known)
}

ServiceDependency defines a dependency on a service

type ServiceRegistry

type ServiceRegistry map[string]any

ServiceRegistry allows registration and retrieval of services

type StdConfigProvider

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

func NewStdConfigProvider

func NewStdConfigProvider(cfg any) *StdConfigProvider

func (*StdConfigProvider) GetConfig

func (s *StdConfigProvider) GetConfig() any

Directories

Path Synopsis
cmd
modcli module
modules
auth module
cache module
chimux module
database module
eventbus module
eventlogger module
httpclient module
httpserver module
jsonschema module
letsencrypt module
logmasker module
reverseproxy module
scheduler module

Jump to

Keyboard shortcuts

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