taler-dashboard/main.go

58 lines
1.3 KiB
Go
Raw Normal View History

2023-12-27 03:06:11 +01:00
package main
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"time"
)
var (
fl_url = flag.String("url", "https://bugs.gnunet.org/api/rest/issues", "URL to the issues")
fl_token = flag.String("token", os.Getenv("MANTIS_API_TOKEN"), "API-Token")
fl_port = flag.String("port", ":8080", "[ip]:port to serve")
fl_num = flag.Int("num", 100, "number of issues to retrieve at once")
2023-12-27 03:16:48 +01:00
fl_min = flag.String("min", "0.9.3", "minimum version we care for")
2023-12-27 03:06:11 +01:00
)
func main() {
flag.Parse()
fmt.Println("starting")
var ctx = context.Background()
var data = NewData(ctx, *fl_url, *fl_token, *fl_num)
data.filterId = 230
data.projectId = 23
data.minimumVersion = *fl_min
data.update()
go func() {
var ticker = time.NewTicker(15 * time.Second)
for range ticker.C {
select {
case <-ctx.Done():
return
default:
fmt.Println("updating data")
data.update()
}
}
}()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
data.printTemplate(w, "table.tmpl")
})
http.HandleFunc("/list", func(w http.ResponseWriter, r *http.Request) {
data.printTemplate(w, "list.tmpl")
})
http.HandleFunc("/json", func(w http.ResponseWriter, r *http.Request) {
data.printJSON(w)
})
fmt.Println("ready to serve")
log.Fatal(http.ListenAndServe(*fl_port, nil))
}