Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename pbs_light.go To main.go #1074

Merged
merged 1 commit into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions pbs_light.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to loadConfig cannot be inlined within the if block since the cfg is needed outside the block. Changing the usage of the server call to match for (hopefully you'll agree) improved readability.

glog.Errorf("prebid-server failed: %v", err)
}
}

func loadConfig() (*config.Configuration, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved the Viper setup logic into its own method to mirror the encapsulation of the server setup. IMHO, this seems easier to read.

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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was quite long. Pulled out the time conversion.

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
}
File renamed without changes.