ussd/internal/handlers/server/balancecheck.go

34 lines
586 B
Go
Raw Normal View History

package server
2024-08-26 11:10:16 +02:00
import (
"encoding/json"
"io"
"net/http"
2024-08-26 11:10:16 +02:00
"git.grassecon.net/urdt/ussd/config"
"git.grassecon.net/urdt/ussd/internal/models"
)
2024-08-26 11:10:16 +02:00
func CheckBalance(publicKey string) (string, error) {
resp, err := http.Get(config.BalanceURL + publicKey)
if err != nil {
return "0.0", err
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return "0.0", err
}
var balanceResp models.BalanceResponse
err = json.Unmarshal(body, &balanceResp)
if err != nil {
return "0.0", err
}
balance := balanceResp.Result.Balance
return balance, nil
}