Refactor
This commit is contained in:
parent
5178558dfc
commit
77a6a6f54c
5
http.go
5
http.go
@ -2,12 +2,13 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
monobank "stuzer.link/monobank-firefly3-bot/monobank/api/webhook/models"
|
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
|
// read body bytes
|
||||||
body, err := io.ReadAll(r.Body)
|
body, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -18,7 +19,7 @@ func readResponseBody(r *http.Request) (monobank.Transaction, error) {
|
|||||||
|
|
||||||
// check empty body
|
// check empty body
|
||||||
if len(string(body)) == 0 {
|
if len(string(body)) == 0 {
|
||||||
return monobank.Transaction{}, err
|
return monobank.Transaction{}, errors.New("empty body")
|
||||||
}
|
}
|
||||||
|
|
||||||
// parse body
|
// parse body
|
||||||
|
@ -25,7 +25,7 @@ func handleWebhook(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// read request
|
// read request
|
||||||
var monobankTransaction monobank.Transaction
|
var monobankTransaction monobank.Transaction
|
||||||
monobankTransaction, err = readResponseBody(r)
|
monobankTransaction, err = readRequestBody(r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
LogString(err.Error())
|
LogString(err.Error())
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user