display time remaining before query limit reset

also add an option to set the refresh interval
This commit is contained in:
Aaron Bieber 2022-12-07 10:58:53 -07:00
parent cb1dd3f69c
commit 7e356e06fa
No known key found for this signature in database
3 changed files with 20 additions and 8 deletions

View File

@ -4,19 +4,22 @@ import (
"bytes" "bytes"
"context" "context"
"encoding/json" "encoding/json"
"github.com/go-chi/chi/v5" "fmt"
"github.com/go-chi/render"
"golang.org/x/image/font"
"golang.org/x/image/font/basicfont"
"golang.org/x/image/math/fixed"
"html/template" "html/template"
"image" "image"
"image/color" "image/color"
"image/png" "image/png"
"net/http" "net/http"
"strconv" "strconv"
"suah.dev/gostart/data" "time"
"unicode" "unicode"
"github.com/go-chi/chi/v5"
"github.com/go-chi/render"
"golang.org/x/image/font"
"golang.org/x/image/font/basicfont"
"golang.org/x/image/math/fixed"
"suah.dev/gostart/data"
) )
// TODO: make this more generic. // TODO: make this more generic.
@ -338,6 +341,11 @@ var templateFuncs = template.FuncMap{
} }
return true return true
}, },
"remaining": func(d time.Time) string {
ct := time.Now()
left := d.Sub(ct)
return fmt.Sprintf("%3.f", left.Minutes())
},
} }
func index(w http.ResponseWriter, r *http.Request) { func index(w http.ResponseWriter, r *http.Request) {

View File

@ -40,6 +40,7 @@ var app = &App{
func main() { func main() {
name := flag.String("name", "startpage", "name of service") name := flag.String("name", "startpage", "name of service")
key := flag.String("key", "", "path to file containing the api key") key := flag.String("key", "", "path to file containing the api key")
watchInterval := flag.Int64("refresh", 5, "number of minutes between watch refresh")
dbFile := flag.String("db", ":memory:", "path to on-disk database file") dbFile := flag.String("db", ":memory:", "path to on-disk database file")
tokenFile := flag.String("auth", "", "path to file containing GH auth token") tokenFile := flag.String("auth", "", "path to file containing GH auth token")
flag.Parse() flag.Parse()
@ -143,7 +144,7 @@ func main() {
if err != nil { if err != nil {
log.Fatal("can't update watches: ", err) log.Fatal("can't update watches: ", err)
} }
time.Sleep(5 * time.Minute) time.Sleep(time.Duration(*watchInterval) * time.Minute)
} }
}() }()

View File

@ -55,7 +55,10 @@
<body> <body>
<header> <header>
<h1>{{.Title}} for {{.Node.ComputedName}}</h1> <h1>{{.Title}} for {{.Node.ComputedName}}</h1>
Remaining queries: {{.CurrentLimits.Remaining}} <p>
Remaining queries: <b>{{.CurrentLimits.Remaining}}</b><br />
Limit resets in <b>{{remaining .CurrentLimits.ResetAt}}</b> minutes.
</p>
</header> </header>
<main> <main>
<div class="grid"> <div class="grid">