aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: 39a269b5b827617ac71a22d69994ee1ad9283cfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main

/*
   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>
*/

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")
	fl_min   = flag.String("min", "0.9.3", "minimum version we care for")
	fl_freq = flag.Duration("fr", time.Minute, "update frequency")
)

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.Freq = *fl_freq

	data.update()
	go func() {
		var ticker = time.NewTicker(*fl_freq)
		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))
}