Architecture change to modules started.

- Added module-interface (module.go).
- Rewritten main function, added Registry (main.go)
This commit is contained in:
Fabian Gasper
2026-07-14 15:50:56 +02:00
parent ed3ffd1d9c
commit 641df9eaab
2 changed files with 82 additions and 81 deletions
+39
View File
@@ -0,0 +1,39 @@
package main
import (
"context"
"net/http"
"github.com/gorilla/mux"
)
// Module represents a self-contained feature of Varde.
// Each module is independently enabled/disabled via config and
// runs in the same process, sharing the HTTP router where relevant.
type Module interface {
// Name returns a short, unique identifier used in logs and config.
Name()
// Enabled reports whether this module should be started
// based on the loaded configuration.
Enabled(cfg *Config) bool
// RegisterRoutes attaches this module's HTTP routes to the shared router, if any.
// Modules without HTTP routes should leave this empty.
RegisterRoutes(r *musx.Router, cfg *Config)
// Start runs any background work for this module (eg. periodic checks, repo cloning).
// Should block until ctx is cancelled, or return immediately if the module has no background work.
Start(ctx context.Context, cfg *Config) error
// Stop performs graceful cleanup. Called druing shutdown for every module that was successfully started.
Stop(ctx context.Context) error
}
// baseModule provides no-op defaults so modules only need to implement the methods relevant to them.
type baseModule struct{}
func (baseModule) RegisterRoutes(r *mux.Router, cfg *Config){}
func (baseModule) Start(cxt context.Context, cfg *Config) error {return nil}
var _ = http.MethodGet // placeholder import guard, remove once a module uses net/http directly here