Ported location recorder
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
@@ -30,6 +31,8 @@ func HandleHaMessage(w http.ResponseWriter, r *http.Request) {
|
||||
switch message.Target {
|
||||
case "poo_recorder":
|
||||
handlePooRecorderMsg(message)
|
||||
case "location_recorder":
|
||||
handleLocationRecorderMsg(message)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -42,6 +45,27 @@ func handlePooRecorderMsg(message haMessage) {
|
||||
|
||||
}
|
||||
|
||||
func handleLocationRecorderMsg(message haMessage) {
|
||||
if message.Action == "record" {
|
||||
port := viper.GetString("port")
|
||||
req, err := http.NewRequest("POST", "http://localhost:"+port+"/location/record", strings.NewReader(strings.ReplaceAll(message.Content, "'", "\"")))
|
||||
if err != nil {
|
||||
slog.Warn(fmt.Sprintln("handleLocationRecorderMsg Error creating request to location recorder", err))
|
||||
return
|
||||
}
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
client := &http.Client{
|
||||
Timeout: time.Second * 1,
|
||||
}
|
||||
_, err = client.Do(req)
|
||||
if err != nil {
|
||||
slog.Warn(fmt.Sprintln("handleLocationRecorderMsg Error sending request to location recorder", err))
|
||||
}
|
||||
} else {
|
||||
slog.Warn(fmt.Sprintln("handleLocationRecorderMsg Unknown action", message.Action))
|
||||
}
|
||||
}
|
||||
|
||||
func handleGetLatestPoo() {
|
||||
client := &http.Client{
|
||||
Timeout: time.Second * 1,
|
||||
|
||||
Reference in New Issue
Block a user