taler-dashboard/main.go

70 lines
2.0 KiB
Go
Raw Normal View History

2023-12-27 03:06:11 +01:00
package main
2023-12-27 03:46:20 +01:00
/*
This file is part of taler-dashboard
Copyright (C) 2023 Özgür Kesim
taler-dashboard is free software; you can redistribute it and/or modify it
under the terms of the GNU Affero General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any later
version.
taler-dashboard is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
License for more details.
You can receive a copy of the GNU Affero General Public License from
<http://www.gnu.org/licenses/>
@author Özgür Kesim <oec-taler@kesim.org>
*/
2023-12-27 03:06:11 +01:00
import (
"context"
"flag"
"fmt"
"log"
"net/http"
"os"
"time"
)
var (
2023-12-27 13:20:51 +01:00
fl_url = flag.String("url", "https://bugs.gnunet.org/api/rest", "URL to the issues")
2023-12-27 03:06:11 +01:00
fl_token = flag.String("token", os.Getenv("MANTIS_API_TOKEN"), "API-Token")
fl_port = flag.String("port", ":8080", "[ip]:port to serve")
2023-12-27 13:20:51 +01:00
fl_num = flag.Int("num", 250, "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 13:20:51 +01:00
fl_freq = flag.Duration("fr", time.Minute, "update frequency")
fl_proj = flag.Int("project", 23, "project id to use")
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)
2023-12-27 13:20:51 +01:00
data.projectId = *fl_proj
2023-12-27 03:06:11 +01:00
data.minimumVersion = *fl_min
2023-12-27 04:18:58 +01:00
data.Freq = *fl_freq
2023-12-27 03:06:11 +01:00
2023-12-27 13:20:51 +01:00
data.Loop()
2023-12-27 03:06:11 +01:00
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
2023-12-27 04:40:24 +01:00
log.Println("got request for table")
2023-12-27 03:06:11 +01:00
data.printTemplate(w, "table.tmpl")
})
http.HandleFunc("/list", func(w http.ResponseWriter, r *http.Request) {
2023-12-27 04:40:24 +01:00
log.Println("got request for list")
2023-12-27 03:06:11 +01:00
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))
}