diff options
author | Martin Polden <mpolden@mpolden.no> | 2020-05-06 20:30:17 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2020-05-06 20:30:38 +0200 |
commit | 6720f896c09b1d52d41ea4d72db9aa63bf9fb66f (patch) | |
tree | 4b45ad684190a9f136acbd91e5f6f812a6b70a6c | |
parent | 02a76677b452c41b1941e98ed03db992cfb86a2e (diff) |
Remove go-flags dependency
-rw-r--r-- | cmd/atbapi/main.go | 34 | ||||
-rw-r--r-- | go.mod | 5 | ||||
-rw-r--r-- | go.sum | 2 |
3 files changed, 19 insertions, 22 deletions
diff --git a/cmd/atbapi/main.go b/cmd/atbapi/main.go index 48a1673..c7bd25d 100644 --- a/cmd/atbapi/main.go +++ b/cmd/atbapi/main.go @@ -1,37 +1,39 @@ package main import ( + "flag" "log" - "os" "time" - flags "github.com/jessevdk/go-flags" "github.com/mpolden/atbapi/atb" "github.com/mpolden/atbapi/http" ) -func main() { - var opts struct { - Listen string `short:"l" long:"listen" description:"Listen address" value-name:"ADDRESS" default:":8080"` - Config string `short:"c" long:"config" description:"Path to config file" value-name:"FILE" default:"config.json"` - StopTTL time.Duration `short:"s" long:"stops-ttl" description:"Bus stop cache duration" value-name:"DURATION" default:"168h"` - DepartureTTL time.Duration `short:"d" long:"departure-ttl" description:"Departure cache duration" value-name:"DURATION" default:"1m"` - CORS bool `short:"x" long:"cors" description:"Allow requests from other domains"` - } - _, err := flags.ParseArgs(&opts, os.Args) +func mustParseDuration(s string) time.Duration { + d, err := time.ParseDuration(s) if err != nil { - os.Exit(1) + 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() - client, err := atb.NewFromConfig(opts.Config) + client, err := atb.NewFromConfig(*config) if err != nil { log.Fatal(err) } - server := http.New(client, opts.StopTTL, opts.DepartureTTL, opts.CORS) + server := http.New(client, mustParseDuration(*stopTTL), mustParseDuration(*departureTTL), *cors) - log.Printf("Listening on %s", opts.Listen) - if err := server.ListenAndServe(opts.Listen); err != nil { + log.Printf("Listening on %s", *listen) + if err := server.ListenAndServe(*listen); err != nil { log.Fatal(err) } } @@ -2,7 +2,4 @@ module github.com/mpolden/atbapi go 1.13 -require ( - github.com/jessevdk/go-flags v1.4.0 - github.com/pmylund/go-cache v2.1.0+incompatible -) +require github.com/pmylund/go-cache v2.1.0+incompatible @@ -1,4 +1,2 @@ -github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA= -github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/pmylund/go-cache v2.1.0+incompatible h1:n+7K51jLz6a3sCvff3BppuCAkixuDHuJ/C57Vw/XjTE= github.com/pmylund/go-cache v2.1.0+incompatible/go.mod h1:hmz95dGvINpbRZGsqPcd7B5xXY5+EKb5PpGhQY3NTHk= |