mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge branch 'pihole_5_api_compat' of github.com:jonhadfield/wtf into jonhadfield-pihole_5_api_compat
This commit is contained in:
commit
35505394d1
@ -23,9 +23,9 @@ type Status struct {
|
||||
Status string `json:"status"`
|
||||
GravityLastUpdated struct {
|
||||
Relative struct {
|
||||
Days string `json:"days"`
|
||||
Hours string `json:"hours"`
|
||||
Minutes string `json:"minutes"`
|
||||
Days FlexInt `json:"days"`
|
||||
Hours FlexInt `json:"hours"`
|
||||
Minutes FlexInt `json:"minutes"`
|
||||
}
|
||||
} `json:"gravity_last_updated"`
|
||||
}
|
||||
@ -76,13 +76,36 @@ func getStatus(c http.Client, apiURL string) (status Status, err error) {
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(rBody, &status); err != nil {
|
||||
return status, fmt.Errorf(" failed to retrieve top items: check provided api URL and token\n %s",
|
||||
return status, fmt.Errorf(" failed to retrieve status: check provided api URL and token\n %s",
|
||||
parseError(err))
|
||||
}
|
||||
|
||||
return status, err
|
||||
}
|
||||
|
||||
type FlexInt int
|
||||
|
||||
func (fi *FlexInt) UnmarshalJSON(b []byte) error {
|
||||
if b[0] != '"' {
|
||||
return json.Unmarshal(b, (*int)(fi))
|
||||
}
|
||||
|
||||
var s string
|
||||
|
||||
if err := json.Unmarshal(b, &s); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i, err := strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*fi = FlexInt(i)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type TopItems struct {
|
||||
TopQueries map[string]int `json:"top_queries"`
|
||||
TopAds map[string]int `json:"top_ads"`
|
||||
|
@ -38,7 +38,7 @@ func getSummaryView(c http.Client, settings *Settings) string {
|
||||
summaryTable := createTable([]string{}, buf)
|
||||
summaryTable.Append([]string{"Domain blocklist", s.DomainsBeingBlocked, "Queries today", s.DNSQueriesToday})
|
||||
summaryTable.Append([]string{"Ads blocked today", fmt.Sprintf("%s (%s%%)", s.AdsBlockedToday, s.AdsPercentageToday), "Cached queries", s.QueriesCached})
|
||||
summaryTable.Append([]string{"Blocklist Age", fmt.Sprintf("%sd %sh %sm", s.GravityLastUpdated.Relative.Days,
|
||||
summaryTable.Append([]string{"Blocklist Age", fmt.Sprintf("%dd %dh %dm", s.GravityLastUpdated.Relative.Days,
|
||||
s.GravityLastUpdated.Relative.Hours, s.GravityLastUpdated.Relative.Minutes), "Forwarded queries", s.QueriesForwarded})
|
||||
summaryTable.Render()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user