diff options
Diffstat (limited to 'internal')
-rw-r--r-- | internal/webui/webui.go | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/internal/webui/webui.go b/internal/webui/webui.go index 6ce5bb4..1a251f4 100644 --- a/internal/webui/webui.go +++ b/internal/webui/webui.go @@ -19,6 +19,20 @@ func Run(c *config.Config, dbEnv *database.DBEnv) { http.Handle("/login", handler{&e, loginHandler}) http.Handle("/static/", http.FileServer(http.FS(staticFS))) + if i, err := dbEnv.CountTrainStops(); err == nil && i == 0 { + log.Printf("No trains stops data found, updating...") + if trainStops, err := e.navitia.GetTrainStops(); err == nil { + log.Printf("Updated trains stops data from navitia api, got %d results", len(trainStops)) + if err = dbEnv.ReplaceAndImportTrainStops(trainStops); err != nil { + if dberr, ok := err.(*database.QueryError); ok { + log.Printf("%+v", dberr.Unwrap()) + } + } + } else { + log.Printf("Failed to get trains stops data from navitia api : %+v", err) + } + } + listenStr := c.Address + ":" + c.Port log.Printf("Starting webui on %s", listenStr) log.Fatal(http.ListenAndServe(listenStr, nil)) |