modutil

package
v0.0.15 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2025 License: MIT Imports: 10 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	Bus         *bus.Bus
	KV          kv.KV
	Log         *slog.Logger
	Web         Web
	StoragePath string
	CachePath   string
}

Deps carries the deps of the modules system itself, not deps for a specific module

type Module

type Module interface {
	Start(context.Context, *ModuleDeps) error
}

A Module can be started with context and deps

type ModuleBase

type ModuleBase struct {
	Log *slog.Logger
	// contains filtered or unexported fields
}

ModuleBase provides some common module functionality

func (*ModuleBase) Go

func (mb *ModuleBase) Go(fn func() error)

Go launches a goroutine with the provided function using the internal errgroup

func (*ModuleBase) MarshalMessage

func (mb *ModuleBase) MarshalMessage(msg *bus.BusMessage, v proto.Message)

MarshalMessage marshals a payload and sets it on the provided BusMessage. If marshalling fails, an error is logged and msg.Error is set

func (*ModuleBase) UnmarshalMessage

func (mb *ModuleBase) UnmarshalMessage(msg *bus.BusMessage, v protoreflect.ProtoMessage) *bus.Error

UnmarshalMessage unmarshals a payload from a BusMessage. If unmarshalling fails, an error is logged and a *bus.Error is returned. A useful idiom is:

if reply.Error = m.UnmarshallMessage(msg, target); reply.Error != nil {
    return reply
}

func (*ModuleBase) Wait

func (mb *ModuleBase) Wait() error

Wait for the internal errgroup to finish.

type ModuleDeps

type ModuleDeps struct {
	Bus         *bus.Bus
	KV          kv.KVPrefix
	Log         *slog.Logger
	StoragePath string
	CachePath   string
}

ModuleDeps carries the deps specific to a module.

type Web

type Web interface {
	Handle(path string, handler http.Handler)
}

Web things can handle HTTP requests

Jump to

Keyboard shortcuts

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