Make the port configurable via CLI flag
parent
f52890f58a
commit
b294be3335
2
TODO
2
TODO
|
@ -12,7 +12,7 @@
|
|||
[ ] *.. Add robots.txt.
|
||||
[x] *.. Compile static files into the binary.
|
||||
[ ] *** Read route preferences from env/config.
|
||||
[ ] *.. Make the port configurable via CLI option.
|
||||
[x] *.. Make the port configurable via CLI option.
|
||||
[ ] *.. Make the stop name link to Breng's page for that stop.
|
||||
[ ] *.. Make the route name link to Breng's page for that route.
|
||||
|
||||
|
|
8
main.go
8
main.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -37,6 +38,11 @@ var BusClient *http.Client
|
|||
var Quays []Quay = []Quay{}
|
||||
|
||||
func main() {
|
||||
var port int
|
||||
|
||||
flag.IntVar(&port, "p", 4444, "The port to start the server on")
|
||||
flag.Parse()
|
||||
|
||||
BusClient = &http.Client{}
|
||||
serveHttp()
|
||||
serveHttp(port)
|
||||
}
|
||||
|
|
|
@ -2,9 +2,11 @@ package main
|
|||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -30,13 +32,13 @@ func formatTime(t time.Time) string {
|
|||
|
||||
var tplFunctions = template.FuncMap{"formatTime": formatTime}
|
||||
|
||||
func serveHttp() {
|
||||
func serveHttp(port int) {
|
||||
http.HandleFunc("/", handleIndex)
|
||||
http.Handle("/static/", http.FileServer(http.FS(staticDir)))
|
||||
|
||||
log.Println("Serving on port 4444")
|
||||
log.Printf("Listening on port %s\n", strconv.Itoa(port))
|
||||
|
||||
err := http.ListenAndServe(":4444", nil)
|
||||
err := http.ListenAndServe(fmt.Sprintf(":%s", strconv.Itoa(port)), nil)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue