corrects payload read/parse functionality
This commit is contained in:
parent
0c1d1e21be
commit
9e57a529f6
@ -1,13 +1,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"tplink/internal/tplink"
|
||||
)
|
||||
|
||||
@ -198,9 +201,19 @@ func tmpltTPlinkGet(w http.ResponseWriter, r *http.Request) {
|
||||
func tmpltTPlinkPost(w http.ResponseWriter, r *http.Request) {
|
||||
var payload alertmanagerStruct
|
||||
|
||||
err := json.NewDecoder(r.Body).Decode(&payload)
|
||||
// read body
|
||||
defer r.Body.Close()
|
||||
b, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
log.Printf("[TRACE] Data received: %#v\n", r.Body)
|
||||
log.Printf("[DEBUG] Unable to read post body from request: %v\n", err)
|
||||
tmpltError(w, http.StatusInternalServerError, fmt.Sprintf("Unable to read post body from request: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
// unmarshal body
|
||||
err = json.Unmarshal(b, &payload)
|
||||
if err != nil {
|
||||
log.Printf("[TRACE] Data received: %#v\n", string(b))
|
||||
log.Printf("[INFO] Unable to parse payload from API call: %v\n", err)
|
||||
tmpltError(w, http.StatusInternalServerError, fmt.Sprintf("Unable to read info from device: %v\n", err))
|
||||
return
|
||||
|
Loading…
x
Reference in New Issue
Block a user