mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-400 IPAPI extracted to new config format
This commit is contained in:
parent
92c2cfc498
commit
0b6a589827
3
main.go
3
main.go
@ -232,7 +232,8 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
|
||||
settings := hackernews.NewSettingsFromYAML(wtf.Config)
|
||||
widget = hackernews.NewWidget(app, pages, settings)
|
||||
case "ipapi":
|
||||
widget = ipapi.NewWidget(app)
|
||||
settings := ipapi.NewSettingsFromYAML(wtf.Config)
|
||||
widget = ipapi.NewWidget(app, settings)
|
||||
case "ipinfo":
|
||||
widget = ipinfo.NewWidget(app)
|
||||
case "jenkins":
|
||||
|
29
modules/ipaddresses/ipapi/settings.go
Normal file
29
modules/ipaddresses/ipapi/settings.go
Normal file
@ -0,0 +1,29 @@
|
||||
package ipapi
|
||||
|
||||
import (
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
)
|
||||
|
||||
type colors struct {
|
||||
name string
|
||||
value string
|
||||
}
|
||||
|
||||
type Settings struct {
|
||||
colors
|
||||
common *cfg.Common
|
||||
}
|
||||
|
||||
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
|
||||
localConfig, _ := ymlConfig.Get("wtf.mods.ipapi")
|
||||
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
|
||||
}
|
||||
|
||||
settings.colors.name = localConfig.UString("colors.name", "red")
|
||||
settings.colors.value = localConfig.UString("colors.value", "white")
|
||||
|
||||
return &settings
|
||||
}
|
@ -15,10 +15,9 @@ import (
|
||||
// Widget widget struct
|
||||
type Widget struct {
|
||||
wtf.TextWidget
|
||||
result string
|
||||
colors struct {
|
||||
name, value string
|
||||
}
|
||||
|
||||
result string
|
||||
settings *Settings
|
||||
}
|
||||
|
||||
type ipinfo struct {
|
||||
@ -37,15 +36,15 @@ type ipinfo struct {
|
||||
}
|
||||
|
||||
// NewWidget constructor
|
||||
func NewWidget(app *tview.Application) *Widget {
|
||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||
widget := Widget{
|
||||
TextWidget: wtf.NewTextWidget(app, "IPInfo", "ipapi", false),
|
||||
|
||||
settings: settings,
|
||||
}
|
||||
|
||||
widget.View.SetWrap(false)
|
||||
|
||||
widget.config()
|
||||
|
||||
return &widget
|
||||
}
|
||||
|
||||
@ -80,13 +79,6 @@ func (widget *Widget) ipinfo() {
|
||||
widget.setResult(&info)
|
||||
}
|
||||
|
||||
// read module configs
|
||||
func (widget *Widget) config() {
|
||||
nameColor, valueColor := wtf.Config.UString("wtf.mods.ipinfo.colors.name", "red"), wtf.Config.UString("wtf.mods.ipinfo.colors.value", "white")
|
||||
widget.colors.name = nameColor
|
||||
widget.colors.value = valueColor
|
||||
}
|
||||
|
||||
func (widget *Widget) setResult(info *ipinfo) {
|
||||
resultTemplate, _ := template.New("ipinfo_result").Parse(
|
||||
formatableText("IP Address", "Ip") +
|
||||
@ -104,8 +96,8 @@ func (widget *Widget) setResult(info *ipinfo) {
|
||||
resultBuffer := new(bytes.Buffer)
|
||||
|
||||
resultTemplate.Execute(resultBuffer, map[string]string{
|
||||
"nameColor": widget.colors.name,
|
||||
"valueColor": widget.colors.value,
|
||||
"nameColor": widget.settings.colors.name,
|
||||
"valueColor": widget.settings.colors.value,
|
||||
"Ip": info.Query,
|
||||
"ISP": info.ISP,
|
||||
"AS": info.AS,
|
||||
|
Loading…
x
Reference in New Issue
Block a user