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
|
package main
import (
"flag"
"log"
"time"
"github.com/mpolden/atb/atb"
"github.com/mpolden/atb/entur"
"github.com/mpolden/atb/http"
)
func init() {
log.SetPrefix("atb: ")
log.SetFlags(log.Lshortfile)
}
func mustParseDuration(s string) time.Duration {
d, err := time.ParseDuration(s)
if err != nil {
log.Fatal(err)
}
return d
}
func main() {
listen := flag.String("l", ":8080", "Listen address")
config := flag.String("c", "config.json", "Path to config file")
stopTTL := flag.String("s", "168h", "Bus stop cache duration")
departureTTL := flag.String("d", "1m", "Departure cache duration")
cors := flag.Bool("x", false, "Allow requests from other domains")
flag.Parse()
atb, err := atb.NewFromConfig(*config)
if err != nil {
log.Fatal(err)
}
entur := entur.New("")
server := http.New(atb, entur, mustParseDuration(*stopTTL), mustParseDuration(*departureTTL), *cors)
log.Printf("Listening on %s", *listen)
if err := server.ListenAndServe(*listen); err != nil {
log.Fatal(err)
}
}
|