display time remaining before query limit reset
also add an option to set the refresh interval
This commit is contained in:
parent
cb1dd3f69c
commit
7e356e06fa
20
handlers.go
20
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) {
|
||||
|
3
main.go
3
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)
|
||||
}
|
||||
|
||||
}()
|
||||
|
@ -55,7 +55,10 @@
|
||||
<body>
|
||||
<header>
|
||||
<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>
|
||||
<main>
|
||||
<div class="grid">
|
||||
|
Loading…
Reference in New Issue
Block a user