From 77a6a6f54cb298a6f0a630a8159ca821151d510c Mon Sep 17 00:00:00 2001 From: stuzer05 Date: Fri, 5 Apr 2024 17:12:28 +0300 Subject: [PATCH] Refactor --- http.go | 5 +++-- webhook.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/http.go b/http.go index c8019a3..d4cb736 100644 --- a/http.go +++ b/http.go @@ -2,12 +2,13 @@ package main import ( "encoding/json" + "errors" "io" "net/http" monobank "stuzer.link/monobank-firefly3-bot/monobank/api/webhook/models" ) -func readResponseBody(r *http.Request) (monobank.Transaction, error) { +func readRequestBody(r *http.Request) (monobank.Transaction, error) { // read body bytes body, err := io.ReadAll(r.Body) if err != nil { @@ -18,7 +19,7 @@ func readResponseBody(r *http.Request) (monobank.Transaction, error) { // check empty body if len(string(body)) == 0 { - return monobank.Transaction{}, err + return monobank.Transaction{}, errors.New("empty body") } // parse body diff --git a/webhook.go b/webhook.go index f631529..a25bba7 100644 --- a/webhook.go +++ b/webhook.go @@ -25,7 +25,7 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) { // read request var monobankTransaction monobank.Transaction - monobankTransaction, err = readResponseBody(r) + monobankTransaction, err = readRequestBody(r) if err != nil { LogString(err.Error()) w.WriteHeader(http.StatusOK)