|
|
|
@ -2,6 +2,7 @@ package main |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"encoding/json" |
|
|
|
|
"errors" |
|
|
|
|
"flag" |
|
|
|
|
"fmt" |
|
|
|
|
"log" |
|
|
|
@ -11,9 +12,11 @@ import ( |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
var ( |
|
|
|
|
addr = ":8080" |
|
|
|
|
statusFile = "./status.json" |
|
|
|
|
webPrefix = "" |
|
|
|
|
addr = ":8080" |
|
|
|
|
statusFile = "./status.json" |
|
|
|
|
webPrefix = "" |
|
|
|
|
xmppJid = "" |
|
|
|
|
xmppPassword = "" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
func main() { |
|
|
|
@ -22,6 +25,8 @@ 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.StringVar(&xmppJid, "xmpp-jid", xmppJid, "JID of XMPP user.") |
|
|
|
|
flag.StringVar(&xmppPassword, "xmpp-password", xmppPassword, "Password of XMPP user.") |
|
|
|
|
flag.Parse() |
|
|
|
|
|
|
|
|
|
storage, err := spaceapi.Open(statusFile, false) |
|
|
|
@ -29,6 +34,12 @@ func main() { |
|
|
|
|
log.Fatalf("Error opening data file: %s", err) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if xmppJid != "" { |
|
|
|
|
if err := createXMPPListener(storage, xmppJid, xmppPassword); err != nil { |
|
|
|
|
log.Printf("Error creating XMPP listemer: %s", err) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
http.Handle(webPrefix+"/status.json", handleReadStatus(storage.Status)) |
|
|
|
|
http.Handle(webPrefix+"/status/state", handleSetState(storage)) |
|
|
|
|
http.Handle("/", http.RedirectHandler(webPrefix+"/status.json", http.StatusFound)) |
|
|
|
@ -72,3 +83,7 @@ func handleSetState(storage *spaceapi.Storage) http.Handler { |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func createXMPPListener(storage *spaceapi.Storage, jid, password string) error { |
|
|
|
|
return errors.New("not implemented") |
|
|
|
|
} |
|
|
|
|