-
Notifications
You must be signed in to change notification settings - Fork 758
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
There was a problem hiding this comment.
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 thecfg
is needed outside the block. Changing the usage of the server call to match for (hopefully you'll agree) improved readability.