From 608f998d0ab796e3f5beae37efa92b3bd8931350 Mon Sep 17 00:00:00 2001 From: Annika Hannig Date: Wed, 20 Oct 2021 18:36:30 +0000 Subject: [PATCH] updated initialization --- cmd/alice-lg/main.go | 22 +++++++++---------- pkg/config/config.go | 10 ++------- pkg/{backend => store}/neighbours_store.go | 2 +- .../neighbours_store_test.go | 2 +- pkg/{backend => store}/routes_store.go | 2 +- pkg/{backend => store}/routes_store_test.go | 2 +- pkg/{backend => store}/store.go | 4 +++- pkg/{backend => store}/store_stats.go | 2 +- 8 files changed, 20 insertions(+), 26 deletions(-) rename pkg/{backend => store}/neighbours_store.go (99%) rename pkg/{backend => store}/neighbours_store_test.go (99%) rename pkg/{backend => store}/routes_store.go (99%) rename pkg/{backend => store}/routes_store_test.go (99%) rename pkg/{backend => store}/store.go (83%) rename pkg/{backend => store}/store_stats.go (99%) diff --git a/cmd/alice-lg/main.go b/cmd/alice-lg/main.go index 66f467b..231bda9 100644 --- a/cmd/alice-lg/main.go +++ b/cmd/alice-lg/main.go @@ -4,7 +4,7 @@ import ( "flag" "log" - "github.com/alice-lg/alice-lg/pkg/backend" + "github.com/alice-lg/alice-lg/pkg/store" ) func main() { @@ -19,31 +19,29 @@ func main() { flag.Parse() // Load configuration - if err := backend.InitConfig(*configFilenameFlag); err != nil { + cfg, err = config.LoadConfig(filename) + if err != nil { log.Fatal(err) } // Say hi printBanner() - - log.Println("Using configuration:", backend.AliceConfig.File) + log.Println("Using configuration:", cfg.File) // Setup local routes store - backend.InitStores() + neighborsStore := store.NewNeighborsStore(cfg) + routesStore := store.NewRoutesStore(cfg) // Start stores if backend.AliceConfig.Server.EnablePrefixLookup == true { - go backend.AliceRoutesStore.Start() - } - - // Setup local neighbours store - if backend.AliceConfig.Server.EnablePrefixLookup == true { - go backend.AliceNeighboursStore.Start() + go neighborsStore.Start() + go routesStore.Start() } // Start the Housekeeping - go backend.Housekeeping(backend.AliceConfig) + go store.Housekeeping(cfg) + // Start HTTP API go backend.StartHTTPServer() <-quit diff --git a/pkg/config/config.go b/pkg/config/config.go index 0437dd1..72fa1c7 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -787,14 +787,8 @@ func getSources(config *ini.File) ([]*SourceConfig, error) { return sources, nil } -// Try to load configfiles as specified in the files -// list. For example: -// -// ./etc/alice-lg/alice.conf -// /etc/alice-lg/alice.conf -// ./etc/alice-lg/alice.local.conf -// -func loadConfig(file string) (*Config, error) { +// Try to load the config file +func LoadConfig(file string) (*Config, error) { // Try to get config file, fallback to alternatives file, err := getConfigFile(file) diff --git a/pkg/backend/neighbours_store.go b/pkg/store/neighbours_store.go similarity index 99% rename from pkg/backend/neighbours_store.go rename to pkg/store/neighbours_store.go index 084fb1c..f44d85c 100644 --- a/pkg/backend/neighbours_store.go +++ b/pkg/store/neighbours_store.go @@ -1,4 +1,4 @@ -package backend +package store import ( "log" diff --git a/pkg/backend/neighbours_store_test.go b/pkg/store/neighbours_store_test.go similarity index 99% rename from pkg/backend/neighbours_store_test.go rename to pkg/store/neighbours_store_test.go index c0a186c..ddf62f3 100644 --- a/pkg/backend/neighbours_store_test.go +++ b/pkg/store/neighbours_store_test.go @@ -1,4 +1,4 @@ -package backend +package store import ( "sort" diff --git a/pkg/backend/routes_store.go b/pkg/store/routes_store.go similarity index 99% rename from pkg/backend/routes_store.go rename to pkg/store/routes_store.go index ffece03..7936443 100644 --- a/pkg/backend/routes_store.go +++ b/pkg/store/routes_store.go @@ -1,4 +1,4 @@ -package backend +package routes import ( "log" diff --git a/pkg/backend/routes_store_test.go b/pkg/store/routes_store_test.go similarity index 99% rename from pkg/backend/routes_store_test.go rename to pkg/store/routes_store_test.go index 2ad5122..c5b04c9 100644 --- a/pkg/backend/routes_store_test.go +++ b/pkg/store/routes_store_test.go @@ -1,4 +1,4 @@ -package backend +package store import ( "log" diff --git a/pkg/backend/store.go b/pkg/store/store.go similarity index 83% rename from pkg/backend/store.go rename to pkg/store/store.go index 6eda642..1632749 100644 --- a/pkg/backend/store.go +++ b/pkg/store/store.go @@ -1,4 +1,6 @@ -package backend +// Package store provides a store for persisting and +// querying neighbors and routes. +package store import ( "time" diff --git a/pkg/backend/store_stats.go b/pkg/store/store_stats.go similarity index 99% rename from pkg/backend/store_stats.go rename to pkg/store/store_stats.go index f72e197..8bdfb82 100644 --- a/pkg/backend/store_stats.go +++ b/pkg/store/store_stats.go @@ -1,4 +1,4 @@ -package backend +package store import ( "log"