From 97ba649df2e156bff5c8ca21d7ba811fa0120441 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 6 Apr 2021 16:04:06 +0200 Subject: Added a flag to specify a configuration file and wrote a proper readme --- README.md | 52 +++++++++++++++++++++++++++++++++++++++++++----- cmd/trains-webui/main.go | 13 +++++++++++- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 23ea7e2..8ee6ae3 100644 --- a/README.md +++ b/README.md @@ -2,16 +2,52 @@ Trains is a simple web app to display train timetables for specific lines at stations on France SNCF's network. It records weekly passages and you can subscribe to certain train times to alert when schedules change or your stop is removed. It queries the SNCF official api by default but will work with any compatible Navitia api implementation and present the results in a minimal web page that loads fast (unlike the official sites with all their images and ads). +A personal instance runs at https://trains.adyxax.org/. + ## Content - [Dependencies](#dependencies) -- [Building](#building) +- [Quick install](#quick-install) +- [Configuration](#configuration) - [Usage](#usage) +- [Building](#building) +- [References](#references) ## Dependencies go is required. Only go version >= 1.16 on linux amd64 (Gentoo and Ubuntu 20.04) and on OpenBSD amd64 has been tested. +## Quick Install + +``` +go install git.adyxax.org/adyxax/trains/cmd/trains-webui@latest +``` + +## Configuration + +The default configuration file location is `$HOME/.config/trains/config.yaml`. It is a yaml configuration file that should look like the following : + +``` +address: 127.0.0.1 +port: 8082 +token: 12345678-9abc-def0-1234-56789abcdef0 +``` + +`address` can be any ipv4 or ipv6 address or a hostname that resolves to such address, `port` can be any valid tcp port number or service name. + +You can get a free token from the [official SNCF's website](https://www.digital.sncf.com/startup/api/token-developpeur) for up to 5000 requests per day. + +## Usage + +Launching the webui server is as simple as : +``` +trains-webui -c /path/to/config/file.yaml +``` + +The server will then listen for requests on the specified hostname and port until interrupted or killed. + +Please consider running it behind a reverse proxy, with https. Also even though the static assets are embedded in the program's binary and can be served from there, consider serving the static assets directly from the web server acting as the reverse proxy or a cdn. + ## Building To run tests, use : @@ -21,14 +57,20 @@ go test -cover ./... For a debug build, use : ``` -go build +go build ./cmd/trains-webui/ ``` For a release build, use : ``` -go build -ldflags="-s -w" +go build -ldflags="-s -w" ./cmd/trains-webui/ ``` -## Usage +To cross-compile for another os or architecture, use : +``` +GOOS=openbsd GOARCH=amd64 go build -ldflags="-s -w" ./cmd/trains-webui/ +``` + +## References -TODO +- https://www.digital.sncf.com/startup/api +- http://doc.navitia.io/ diff --git a/cmd/trains-webui/main.go b/cmd/trains-webui/main.go index 76f34ea..0ea3b57 100644 --- a/cmd/trains-webui/main.go +++ b/cmd/trains-webui/main.go @@ -1,14 +1,25 @@ package main import ( + "flag" "log" + "os" "git.adyxax.org/adyxax/trains/internal/webui" "git.adyxax.org/adyxax/trains/pkg/config" ) func main() { - c, err := config.LoadFile("/home/julien/.config/adyxax-trains/config.yaml") + path := flag.String("c", os.Getenv("HOME")+"/.config/trains/config.yaml", "configuration file path") + help := flag.Bool("h", false, "display this help message") + flag.Parse() + + if *help { + flag.Usage() + os.Exit(0) + } + + c, err := config.LoadFile(*path) if err != nil { log.Fatal(err) } -- cgit v1.2.3