1/*2Maddy Mail Server - Composable all-in-one email server.3Copyright © 2019-2020 Max Mazurov <fox.cpp@disroot.org>, Maddy Mail Server contributors45This program is free software: you can redistribute it and/or modify6it under the terms of the GNU General Public License as published by7the Free Software Foundation, either version 3 of the License, or8(at your option) any later version.910This program is distributed in the hope that it will be useful,11but WITHOUT ANY WARRANTY; without even the implied warranty of12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the13GNU General Public License for more details.1415You should have received a copy of the GNU General Public License16along with this program. If not, see <https://www.gnu.org/licenses/>.17*/1819// Package module contains modules registry and interfaces implemented20// by modules.21//22// Interfaces are placed here to prevent circular dependencies.23//24// Each interface required by maddy for operation is provided by some object25// called "module". This includes authentication, storage backends, DKIM,26// email filters, etc. Each module may serve multiple functions. I.e. it can27// be IMAP storage backend, SMTP downstream and authentication provider at the28// same moment.29//30// Each module gets its own unique name (sql for go-imap-sql, proxy for31// proxy module, local for local delivery perhaps, etc). Each module instance32// also can have its own unique name can be used to refer to it in33// configuration.34package module3536import (37 "github.com/foxcpp/maddy/framework/config"38)3940// Module is the interface implemented by all maddy module instances.41//42// It defines basic methods used to identify instances.43//44// Additionally, module can implement io.Closer if it needs to perform clean-up45// on shutdown. If module starts long-lived goroutines - they should be stopped46// *before* Close method returns to ensure graceful shutdown.47type Module interface {48 // Init performs actual initialization of the module.49 //50 // It is not done in FuncNewModule so all module instances are51 // registered at time of initialization, thus initialization does not52 // depends on ordering of configuration blocks and modules can reference53 // each other without any problems.54 //55 // Module can use passed config.Map to read its configuration variables.56 Init(*config.Map) error5758 // Name method reports module name.59 //60 // It is used to reference module in the configuration and in logs.61 Name() string6263 // InstanceName method reports unique name of this module instance or empty64 // string if module instance is unnamed.65 InstanceName() string66}6768// FuncNewModule is function that creates new instance of module with specified name.69//70// Module.InstanceName() of the returned module object should return instName.71// aliases slice contains other names that can be used to reference created72// module instance.73//74// If module is defined inline, instName will be empty and all values75// specified after module name in configuration will be in inlineArgs.76type FuncNewModule func(modName, instName string, aliases, inlineArgs []string) (Module, error)7778// FuncNewEndpoint is a function that creates new instance of endpoint79// module.80//81// Compared to regular modules, endpoint module instances are:82// - Not registered in the global registry.83// - Can't be defined inline.84// - Don't have an unique name85// - All config arguments are always passed as an 'addrs' slice and not used as86// names.87//88// As a consequence of having no per-instance name, InstanceName of the module89// object always returns the same value as Name.90type FuncNewEndpoint func(modName string, addrs []string) (Module, error)