diff --git a/backend/main.go b/backend/main.go index 302a4d5..ab093d6 100644 --- a/backend/main.go +++ b/backend/main.go @@ -213,7 +213,8 @@ func main() { // TODO: length checks on body // TODO: extract this shit out image := make([]byte, 0) - if contentType == "application/base64" { + switch contentType { + case "application/base64": decoder := base64.NewDecoder(base64.StdEncoding, r.Body) buf := &bytes.Buffer{} @@ -229,7 +230,7 @@ func main() { fmt.Println(decodedIamge) image = buf.Bytes() - } else if contentType == "application/oclet-stream" || contentType == "image/png" { + case "application/oclet-stream", "image/png": bodyData, err := io.ReadAll(r.Body) if err != nil { log.Println(err) @@ -240,7 +241,7 @@ func main() { // TODO: check headers image = bodyData - } else { + default: log.Println("bad stuff?") w.WriteHeader(http.StatusBadRequest) fmt.Fprintf(w, "Bruh, you need oclet stream or base64")