Remove duplicate handling

This commit is contained in:
idanoo 2022-11-20 17:56:51 +13:00
parent 263bcf9250
commit 8f012fc275
Signed by: idanoo
GPG Key ID: 387387CDBC02F132

14
main.go
View File

@ -2,8 +2,6 @@ package main
import ( import (
"encoding/json" "encoding/json"
"fmt"
"io"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -51,19 +49,7 @@ func main() {
} }
func handler(w http.ResponseWriter, r *http.Request) { func handler(w http.ResponseWriter, r *http.Request) {
var bodyBytes []byte
var err error
if r.Body != nil { if r.Body != nil {
bodyBytes, err = io.ReadAll(r.Body)
if err != nil {
fmt.Printf("Body reading error: %v", err)
return
}
defer r.Body.Close()
}
if len(bodyBytes) > 0 {
var i IdentifyingRequest var i IdentifyingRequest
err := json.NewDecoder(r.Body).Decode(&i) err := json.NewDecoder(r.Body).Decode(&i)
if err != nil { if err != nil {