1
0
mirror of https://github.com/taigrr/wtf synced 2026-03-28 15:15:15 -07:00

Decouple newrelic client and widget

Have widget manage config
Have client handle communication
This commit is contained in:
Sean Smith
2019-02-18 16:55:22 -05:00
parent 8030380f89
commit 29e67a0d8a
2 changed files with 29 additions and 18 deletions

View File

@@ -2,6 +2,7 @@ package newrelic
import (
"fmt"
"os"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/wtf"
@@ -10,11 +11,13 @@ import (
type Widget struct {
wtf.TextWidget
client *Client
}
func NewWidget(app *tview.Application) *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(app, "New Relic", "newrelic", false),
client: NewClient(apiKey(), wtf.Config.UInt("wtf.mods.newrelic.applicationId")),
}
return &widget
@@ -23,8 +26,8 @@ func NewWidget(app *tview.Application) *Widget {
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
app, appErr := Application()
deploys, depErr := Deployments()
app, appErr := widget.client.Application()
deploys, depErr := widget.client.Deployments()
appName := "error"
if appErr == nil {
@@ -86,3 +89,10 @@ 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"),
)
}