go-kernel-mt
A tiny, opinionated "kernel" for modular Go applications.
go-kernel-mt provides:
- A minimal module contract (
ModuleIntf) with two lifecycle hooks:
RegisterPermissions()
ExposeMethods()
- A simple kernel that registers modules by name and runs them in order:
- calls
RegisterPermissions() on all modules
- calls
ExposeMethods() on all modules
- A small
logging package with a global Logger interface and a zerolog implementation.
Install
go get github.com/Marekt94/go-kernel-mt
Quick example
package main
import (
kernel "github.com/Marekt94/go-kernel-mt"
"github.com/Marekt94/go-kernel-mt/logging"
)
type HelloModule struct{}
func (m *HelloModule) GetName() string { return "hello" }
func (m *HelloModule) RegisterPermissions() { /* optional */ }
func (m *HelloModule) ExposeMethods() { logging.Global.Infof("Hello from module") }
func main() {
logging.SetGlobalLogger(logging.NewZerologLogger())
k := kernel.NewKernel()
k.RegisterModule(&HelloModule{})
k.Run()
}
Design notes
- No inheritance / no magic: composition + small interfaces.
- Duplicate module names cause a panic during registration.
Kernel.Init() is currently a no-op and can be used by embedding/wrapping the kernel in your own application type.
Logging
The logging package exposes a global logger (logging.Global) to keep dependencies small and avoid wiring in tiny projects.
- Default logger is a safe
dummyLogger (prints a warning that the logger wasn't initialized).
- Call
logging.SetGlobalLogger(...) to set a real logger.
logging.NewZerologLogger() configures a console zerolog logger.
- You can set the env var
LOG_LEVEL (e.g. trace, debug, info, warn).
License
MIT — see LICENSE.