Remove ParseMonolith/LoadMonolith

This commit is contained in:
Kegan Dougal 2020-06-04 16:36:41 +01:00
parent 2bd12f635c
commit 0069aee426
14 changed files with 17 additions and 58 deletions

View file

@ -21,7 +21,7 @@ import (
)
func main() {
cfg := basecomponent.ParseFlags()
cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "AppServiceAPI", true)
defer base.Close() // nolint: errcheck

View file

@ -23,7 +23,7 @@ import (
)
func main() {
cfg := basecomponent.ParseFlags()
cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "ClientAPI", true)
defer base.Close() // nolint: errcheck

View file

@ -22,7 +22,7 @@ import (
)
func main() {
cfg := basecomponent.ParseFlags()
cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "EDUServerAPI", true)
defer func() {
if err := base.Close(); err != nil {

View file

@ -23,7 +23,7 @@ import (
)
func main() {
cfg := basecomponent.ParseFlags()
cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "FederationAPI", true)
defer base.Close() // nolint: errcheck

View file

@ -20,7 +20,7 @@ import (
)
func main() {
cfg := basecomponent.ParseFlags()
cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "FederationSender", true)
defer base.Close() // nolint: errcheck

View file

@ -20,7 +20,7 @@ import (
)
func main() {
cfg := basecomponent.ParseFlags()
cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "KeyServer", true)
defer base.Close() // nolint: errcheck

View file

@ -20,7 +20,7 @@ import (
)
func main() {
cfg := basecomponent.ParseFlags()
cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "MediaAPI", true)
defer base.Close() // nolint: errcheck

View file

@ -49,7 +49,7 @@ var (
)
func main() {
cfg := basecomponent.ParseMonolithFlags()
cfg := basecomponent.ParseFlags(true)
if *enableHTTPAPIs {
// If the HTTP APIs are enabled then we need to update the Listen
// statements in the configuration so that we know where to find

View file

@ -22,7 +22,7 @@ import (
)
func main() {
cfg := basecomponent.ParseFlags()
cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "PublicRoomsAPI", true)
defer base.Close() // nolint: errcheck

View file

@ -20,7 +20,7 @@ import (
)
func main() {
cfg := basecomponent.ParseFlags()
cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "RoomServerAPI", true)
defer base.Close() // nolint: errcheck
federation := base.CreateFederationClient()

View file

@ -20,7 +20,7 @@ import (
)
func main() {
cfg := basecomponent.ParseFlags()
cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "ServerKeyAPI", true)
defer base.Close() // nolint: errcheck

View file

@ -20,7 +20,7 @@ import (
)
func main() {
cfg := basecomponent.ParseFlags()
cfg := basecomponent.ParseFlags(false)
base := basecomponent.NewBaseDendrite(cfg, "SyncAPI", true)
defer base.Close() // nolint: errcheck

View file

@ -25,33 +25,14 @@ import (
var configPath = flag.String("config", "dendrite.yaml", "The path to the config file. For more information, see the config file in this repository.")
// ParseFlags parses the commandline flags and uses them to create a config.
// If running as a monolith use `ParseMonolithFlags` instead.
func ParseFlags() *config.Dendrite {
func ParseFlags(monolith bool) *config.Dendrite {
flag.Parse()
if *configPath == "" {
logrus.Fatal("--config must be supplied")
}
cfg, err := config.Load(*configPath)
if err != nil {
logrus.Fatalf("Invalid config file: %s", err)
}
return cfg
}
// ParseMonolithFlags parses the commandline flags and uses them to create a
// config. Should only be used if running a monolith. See `ParseFlags`.
func ParseMonolithFlags() *config.Dendrite {
flag.Parse()
if *configPath == "" {
logrus.Fatal("--config must be supplied")
}
cfg, err := config.LoadMonolithic(*configPath)
cfg, err := config.Load(*configPath, monolith)
if err != nil {
logrus.Fatalf("Invalid config file: %s", err)

View file

@ -370,11 +370,9 @@ type LogrusHook struct {
// It implements the error interface.
type configErrors []string
// Load a yaml config file for a server run as multiple processes.
// Load a yaml config file for a server run as multiple processes or as a monolith.
// Checks the config to ensure that it is valid.
// The checks are different if the server is run as a monolithic process instead
// of being split into multiple components
func Load(configPath string) (*Dendrite, error) {
func Load(configPath string, monolith bool) (*Dendrite, error) {
configData, err := ioutil.ReadFile(configPath)
if err != nil {
return nil, err
@ -385,27 +383,7 @@ func Load(configPath string) (*Dendrite, error) {
}
// Pass the current working directory and ioutil.ReadFile so that they can
// be mocked in the tests
monolithic := false
return loadConfig(basePath, configData, ioutil.ReadFile, monolithic)
}
// LoadMonolithic loads a yaml config file for a server run as a single monolith.
// Checks the config to ensure that it is valid.
// The checks are different if the server is run as a monolithic process instead
// of being split into multiple components
func LoadMonolithic(configPath string) (*Dendrite, error) {
configData, err := ioutil.ReadFile(configPath)
if err != nil {
return nil, err
}
basePath, err := filepath.Abs(".")
if err != nil {
return nil, err
}
// Pass the current working directory and ioutil.ReadFile so that they can
// be mocked in the tests
monolithic := true
return loadConfig(basePath, configData, ioutil.ReadFile, monolithic)
return loadConfig(basePath, configData, ioutil.ReadFile, monolith)
}
func loadConfig(