package main import ( "flag" "fmt" "log" "net/http" "github.com/gorilla/mux" ) var ( // Store a list of categories categories []string // Map a category to it's age on disk // If a category is downloaded, it is added to this map with it's Unix epoch // timestamp. // If the category is too old, re-download it // TODO: Define what "to old" acutually means and what default value it // might get categoryAge = make(map[string]int) // Define the port the server should listen on port int ) func main() { // Parse the command line flags initFlags() // Define a new gorilla/mux router and define some endpoints r := mux.NewRouter() r.HandleFunc("/", indexHandler) r.HandleFunc("/dumpall", dumpallHandler) r.HandleFunc("/{station}/{name}", getHandler) // Start the http server using the port provided using command line arguments // The Default port is 8080 log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", port), r)) } func initFlags() { flag.IntVar(&port, "p", 8080, "the port the server should listen on") flag.Parse() }