forked from andig/gravo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
49 lines (39 loc) · 1.31 KB
/
Copy pathmain.go
File metadata and controls
49 lines (39 loc) · 1.31 KB
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
package main
import (
"flag"
"log"
"net/http"
"os"
"time"
"github.com/andig/gravo/volkszaehler"
)
var (
version = "development"
commit = "unknown commit"
timeout = 30 * time.Second
)
var apiURL = flag.String("api", "https://demo.volkszaehler.org/middleware.php", "volkszaehler api url")
var apiTimeout = flag.Duration("timeout", timeout, "volkszaehler api request timeout")
var url = flag.String("url", "0.0.0.0:8000", "listening address")
var verbose = flag.Bool("verbose", false, "verbose logging")
var help = flag.Bool("help", false, "help")
func main() {
log.Printf("Running gravo %s (%s)", version, commit)
flag.Parse()
if *help {
flag.PrintDefaults()
os.Exit(0)
}
httpClient := http.Client{Timeout: *apiTimeout}
client := volkszaehler.NewClient(*apiURL, &httpClient, *verbose)
server := newServer(client)
http.HandleFunc("/", handler(server.rootHandler, *verbose))
http.HandleFunc("/query", handler(server.queryHandler, *verbose))
http.HandleFunc("/search", handler(server.searchHandler, *verbose))
http.HandleFunc("/annotations", handler(server.annotationsHandler, *verbose))
http.HandleFunc("/tag-keys", handler(server.tagKeysHandler, *verbose))
http.HandleFunc("/tag-values", handler(server.tagValuesHandler, *verbose))
if err := http.ListenAndServe(*url, nil); err != nil {
log.Fatal(err)
}
}