From 81b3bfd0798fe46ea0514e8199eab0fb2c41e23f Mon Sep 17 00:00:00 2001 From: Scott Kay Date: Tue, 15 Oct 2019 16:32:32 -0400 Subject: [PATCH] Rename pbs_light.go To main.go --- pbs_light.go => main.go | 23 ++++++++++++++++------- pbs_light_test.go => main_test.go | 0 2 files changed, 16 insertions(+), 7 deletions(-) rename pbs_light.go => main.go (81%) rename pbs_light_test.go => main_test.go (100%) diff --git a/pbs_light.go b/main.go similarity index 81% rename from pbs_light.go rename to main.go index 9b79993887c..ae3b7fd5705 100644 --- a/pbs_light.go +++ b/main.go @@ -31,28 +31,37 @@ func init() { func main() { flag.Parse() // required for glog flags and testing package flags - v := viper.New() - config.SetupViper(v, "pbs") - cfg, err := config.New(v) + cfg, err := loadConfig() if err != nil { glog.Fatalf("Configuration could not be loaded or did not pass validation: %v", err) } - if err := serve(Rev, cfg); err != nil { + + err = serve(Rev, cfg) + if err != nil { glog.Errorf("prebid-server failed: %v", err) } } +func loadConfig() (*config.Configuration, error) { + v := viper.New() + config.SetupViper(v, "pbs") // filke = filename + return config.New(v) +} + func serve(revision string, cfg *config.Configuration) error { - currencyConverter := currencies.NewRateConverter(&http.Client{}, cfg.CurrencyConverter.FetchURL, time.Duration(cfg.CurrencyConverter.FetchIntervalSeconds)*time.Second) + fetchingInterval := time.Duration(cfg.CurrencyConverter.FetchIntervalSeconds) * time.Second + currencyConverter := currencies.NewRateConverter(&http.Client{}, cfg.CurrencyConverter.FetchURL, fetchingInterval) + r, err := router.New(cfg, currencyConverter) if err != nil { return err } - // Init prebid cache + pbc.InitPrebidCache(cfg.CacheURL.GetBaseURL()) - // Add cors support + corsRouter := router.SupportCORS(r) server.Listen(cfg, router.NoCache{Handler: corsRouter}, router.Admin(revision, currencyConverter), r.MetricsEngine) + r.Shutdown() return nil } diff --git a/pbs_light_test.go b/main_test.go similarity index 100% rename from pbs_light_test.go rename to main_test.go