diff --git a/handlers.go b/handlers.go index 678d63e..9e3577c 100644 --- a/handlers.go +++ b/handlers.go @@ -4,19 +4,22 @@ import ( "bytes" "context" "encoding/json" - "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" + "fmt" "html/template" "image" "image/color" "image/png" "net/http" "strconv" - "suah.dev/gostart/data" + "time" "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. @@ -338,6 +341,11 @@ var templateFuncs = template.FuncMap{ } 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) { diff --git a/main.go b/main.go index 1438981..5a4288d 100644 --- a/main.go +++ b/main.go @@ -40,6 +40,7 @@ var app = &App{ func main() { name := flag.String("name", "startpage", "name of service") 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") tokenFile := flag.String("auth", "", "path to file containing GH auth token") flag.Parse() @@ -143,7 +144,7 @@ func main() { if err != nil { log.Fatal("can't update watches: ", err) } - time.Sleep(5 * time.Minute) + time.Sleep(time.Duration(*watchInterval) * time.Minute) } }() diff --git a/templates/main.html b/templates/main.html index c9a7977..63d8d1e 100644 --- a/templates/main.html +++ b/templates/main.html @@ -55,7 +55,10 @@

{{.Title}} for {{.Node.ComputedName}}

- Remaining queries: {{.CurrentLimits.Remaining}} +

+ Remaining queries: {{.CurrentLimits.Remaining}}
+ Limit resets in {{remaining .CurrentLimits.ResetAt}} minutes. +