Files
maddy/framework/container/container.go
fox.cpp 503c9f8849 Implement Configure-Start-Stop module lifetime and non-global Registry object
container.Global is temporarily added until we start passing container
during module initialization.
2025-01-29 21:40:15 +03:00

71 lines
2.2 KiB
Go

/*
Maddy Mail Server - Composable all-in-one email server.
Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package container
import (
"github.com/foxcpp/maddy/framework/log"
"github.com/foxcpp/maddy/framework/module"
)
type GlobalConfig struct {
// StateDirectory contains the path to the directory that
// should be used to store any data that should be
// preserved between sessions.
//
// Value of this variable must not change after initialization
// in cmd/maddy/main.go.
StateDirectory string
// RuntimeDirectory contains the path to the directory that
// should be used to store any temporary data.
//
// It should be preferred over os.TempDir, which is
// global and world-readable on most systems, while
// RuntimeDirectory can be dedicated for maddy.
//
// Value of this variable must not change after initialization
// in cmd/maddy/main.go.
RuntimeDirectory string
// LibexecDirectory contains the path to the directory
// where helper binaries should be searched.
//
// Value of this variable must not change after initialization
// in cmd/maddy/main.go.
LibexecDirectory string
}
type C struct {
Config GlobalConfig
DefaultLogger log.Logger
Modules *module.Registry
Lifetime *module.LifetimeTracker
}
func New() *C {
return &C{
DefaultLogger: log.DefaultLogger,
Modules: module.NewRegistry(log.DefaultLogger.Sublogger("registry")),
Lifetime: module.NewLifetime(log.DefaultLogger.Sublogger("lifetime")),
}
}
// Global is the default instance while refactoring is in progress.
var Global *C