Add prefix parameter.

change-name
Robert Jacob 5 years ago
parent 02646057cc
commit 61cb36b29f
  1. 8
      cmd/spaceapi-server/main.go

@ -13,6 +13,7 @@ import (
var (
addr = ":8080"
statusFile = "./status.json"
webPrefix = ""
)
func main() {
@ -20,6 +21,7 @@ func main() {
flag.StringVar(&addr, "addr", addr, "Network address to listen on.")
flag.StringVar(&statusFile, "status-file", statusFile, "Status file to modify.")
flag.StringVar(&webPrefix, "web-prefix", webPrefix, "Prefix path for web endpoints.")
flag.Parse()
storage, err := spaceapi.Open(statusFile, false)
@ -27,9 +29,9 @@ func main() {
log.Fatalf("Error opening data file: %s", err)
}
http.Handle("/spaceapi/status.json", handleReadStatus(storage.Status))
http.Handle("/spaceapi/status/state", handleSetState(storage))
http.Handle("/", http.RedirectHandler("/spaceapi/status.json", http.StatusFound))
http.Handle(webPrefix+"/status.json", handleReadStatus(storage.Status))
http.Handle(webPrefix+"/status/state", handleSetState(storage))
http.Handle("/", http.RedirectHandler(webPrefix+"/status.json", http.StatusFound))
log.Printf("Listening on %s...", addr)
log.Fatal(http.ListenAndServe(addr, nil))

Loading…
Cancel
Save