From d0d844fd4fb2d12ea4b85b7e822e89cd14ddb9f0 Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Sat, 20 Aug 2022 00:21:52 +0200 Subject: [PATCH] balance check --- internal/api/balance.go | 5 ----- internal/api/invoice.go | 4 ++++ internal/api/lightning.go | 11 ++++++++--- 3 files changed, 12 insertions(+), 8 deletions(-) delete mode 100644 internal/api/balance.go diff --git a/internal/api/balance.go b/internal/api/balance.go deleted file mode 100644 index 36f6e2a..0000000 --- a/internal/api/balance.go +++ /dev/null @@ -1,5 +0,0 @@ -package api - -type BalanceResponse struct { - Balance int64 `json:"balance"` -} diff --git a/internal/api/invoice.go b/internal/api/invoice.go index 7d1fb56..090b714 100644 --- a/internal/api/invoice.go +++ b/internal/api/invoice.go @@ -1,5 +1,9 @@ package api +type BalanceResponse struct { + Balance int64 `json:"balance"` +} + type InvoiceStatusResponse struct { State string `json:"state,omitempty"` PaymentHash string `json:"payment_hash"` diff --git a/internal/api/lightning.go b/internal/api/lightning.go index a1b008e..2fa385f 100644 --- a/internal/api/lightning.go +++ b/internal/api/lightning.go @@ -13,14 +13,14 @@ type Service struct { Bot *telegram.TipBot } -type ApiError struct { +type ErrorResponse struct { Message string `json:"error"` } func RespondError(w http.ResponseWriter, message string) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusBadRequest) - json.NewEncoder(w).Encode(ApiError{Message: message}) + json.NewEncoder(w).Encode(ErrorResponse{Message: message}) } func (s Service) Balance(w http.ResponseWriter, r *http.Request) { @@ -30,9 +30,14 @@ func (s Service) Balance(w http.ResponseWriter, r *http.Request) { RespondError(w, "balance check failed") return } + + balanceResponse := BalanceResponse{ + Balance: balance, + } + w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(balance) + json.NewEncoder(w).Encode(balanceResponse) } func (s Service) CreateInvoice(w http.ResponseWriter, r *http.Request) {