diff --git a/main.go b/main.go index e363fc02..370624ec 100644 --- a/main.go +++ b/main.go @@ -253,7 +253,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w settings := nbascore.NewSettingsFromYAML(wtf.Config) widget = nbascore.NewWidget(app, pages, settings) case "newrelic": - widget = newrelic.NewWidget(app) + settings := newrelic.NewSettingsFromYAML(wtf.Config) + widget = newrelic.NewWidget(app, settings) case "opsgenie": widget = opsgenie.NewWidget(app) case "pagerduty": diff --git a/modules/newrelic/settings.go b/modules/newrelic/settings.go new file mode 100644 index 00000000..0971bf00 --- /dev/null +++ b/modules/newrelic/settings.go @@ -0,0 +1,30 @@ +package newrelic + +import ( + "os" + + "github.com/olebedev/config" + "github.com/wtfutil/wtf/cfg" +) + +type Settings struct { + common *cfg.Common + + apiKey string + applicationID int + deployCount int +} + +func NewSettingsFromYAML(ymlConfig *config.Config) *Settings { + localConfig, _ := ymlConfig.Get("wtf.mods.newrelic") + + settings := Settings{ + common: cfg.NewCommonSettingsFromYAML(ymlConfig), + + apiKey: localConfig.UString("apiKey", os.Getenv("WTF_NEW_RELIC_API_KEY")), + applicationID: localConfig.UInt("applicationID"), + deployCount: localConfig.UInt("deployCount", 5), + } + + return &settings +} diff --git a/modules/newrelic/widget.go b/modules/newrelic/widget.go index 591426c5..1ed7be12 100644 --- a/modules/newrelic/widget.go +++ b/modules/newrelic/widget.go @@ -2,7 +2,6 @@ package newrelic import ( "fmt" - "os" "github.com/rivo/tview" "github.com/wtfutil/wtf/wtf" @@ -11,15 +10,20 @@ import ( type Widget struct { wtf.TextWidget - client *Client + + client *Client + settings *Settings } -func NewWidget(app *tview.Application) *Widget { +func NewWidget(app *tview.Application, settings *Settings) *Widget { widget := Widget{ TextWidget: wtf.NewTextWidget(app, "New Relic", "newrelic", false), - client: NewClient(apiKey(), wtf.Config.UInt("wtf.mods.newrelic.applicationId")), + + settings: settings, } + widget.client = NewClient(widget.settings.apiKey, widget.settings.applicationID) + return &widget } @@ -81,7 +85,7 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { revisions = append(revisions, deploy.Revision) - if len(revisions) == wtf.Config.UInt("wtf.mods.newrelic.deployCount", 5) { + if len(revisions) == widget.settings.deployCount { break } } @@ -89,10 +93,3 @@ func (widget *Widget) contentFrom(deploys []nr.ApplicationDeployment) string { return str } - -func apiKey() string { - return wtf.Config.UString( - "wtf.mods.newrelic.apiKey", - os.Getenv("WTF_NEW_RELIC_API_KEY"), - ) -} diff --git a/modules/todo/settings.go b/modules/todo/settings.go index 6632ff2b..98f4a0f7 100644 --- a/modules/todo/settings.go +++ b/modules/todo/settings.go @@ -15,7 +15,8 @@ func NewSettingsFromYAML(ymlConfig *config.Config) *Settings { localConfig, _ := ymlConfig.Get("wtf.mods.todo") settings := Settings{ - common: cfg.NewCommonSettingsFromYAML(ymlConfig), + common: cfg.NewCommonSettingsFromYAML(ymlConfig), + filePath: localConfig.UString("filename"), }