mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Clean up the Weather module's API credentials loading
Now prioritizes API key configuration in the config file over ENV vars.
This commit is contained in:
parent
9ddd514631
commit
c7223843f0
@ -1,13 +1,13 @@
|
||||
package weather
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
//"fmt"
|
||||
"os"
|
||||
|
||||
owm "github.com/briandowns/openweathermap"
|
||||
"github.com/gdamore/tcell"
|
||||
"github.com/rivo/tview"
|
||||
"github.com/senorprogrammer/wtf/logger"
|
||||
//"github.com/senorprogrammer/wtf/logger"
|
||||
"github.com/senorprogrammer/wtf/wtf"
|
||||
)
|
||||
|
||||
@ -43,14 +43,10 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
|
||||
app: app,
|
||||
pages: pages,
|
||||
|
||||
APIKey: os.Getenv("WTF_OWM_API_KEY"),
|
||||
Idx: 0,
|
||||
}
|
||||
|
||||
if widget.APIKey == "" {
|
||||
logger.Log("loading weather API key from config")
|
||||
widget.APIKey = wtf.Config.UString(fmt.Sprintf("wtf.mods.%s.apiKey", configKey), "")
|
||||
}
|
||||
widget.loadAPICredentials()
|
||||
|
||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||
|
||||
@ -188,6 +184,15 @@ func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||
}
|
||||
}
|
||||
|
||||
// loadAPICredentials loads the API authentication credentials for this module
|
||||
// First checks to see if they're in the config file. If not, checks the ENV var
|
||||
func (widget *Widget) loadAPICredentials() {
|
||||
widget.APIKey = wtf.Config.UString(
|
||||
"wtf.mods.weather.apiKey",
|
||||
os.Getenv("WTF_OWM_API_KEY"),
|
||||
)
|
||||
}
|
||||
|
||||
func (widget *Widget) showHelp() {
|
||||
closeFunc := func() {
|
||||
widget.pages.RemovePage("help")
|
||||
|
Loading…
x
Reference in New Issue
Block a user