kernel

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 1 Imported by: 0

README

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:
    1. calls RegisterPermissions() on all modules
    2. 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.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kernel

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

func NewKernel

func NewKernel() Kernel

func (*Kernel) Init

func (k *Kernel) Init()

func (*Kernel) RegisterModule

func (k *Kernel) RegisterModule(m ModuleIntf)

func (*Kernel) Run

func (k *Kernel) Run()

type KernelIntf

type KernelIntf interface {
	RegisterModule(m ModuleIntf)
	Run()
	Init()
}

type ModuleIntf

type ModuleIntf interface {
	ExposeMethods()
	RegisterPermissions()
	GetName() string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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