<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: mikecurious</title>
    <description>The latest articles on DEV Community by mikecurious (@mikecurious).</description>
    <link>https://dev.to/mikecurious</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1127089%2Fa964c213-35d3-4d2f-a9cd-f465b656e1d7.jpeg</url>
      <title>DEV Community: mikecurious</title>
      <link>https://dev.to/mikecurious</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mikecurious"/>
    <language>en</language>
    <item>
      <title>I AM STUCK HERE FOR 3 DAYS NOW</title>
      <dc:creator>mikecurious</dc:creator>
      <pubDate>Tue, 27 Feb 2024 16:44:57 +0000</pubDate>
      <link>https://dev.to/mikecurious/i-am-stuck-here-for-3-days-now-58f8</link>
      <guid>https://dev.to/mikecurious/i-am-stuck-here-for-3-days-now-58f8</guid>
      <description>&lt;p&gt;i cant seem to hit this endpoint /check-wallet-balance 'here is my route file"package routes&lt;/p&gt;

&lt;p&gt;import (&lt;br&gt;
    "encoding/json"&lt;br&gt;
    "fmt"&lt;br&gt;
    "io/ioutil"&lt;br&gt;
    "net/http"&lt;br&gt;
    "os"&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"github.com/gin-gonic/gin"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;)&lt;/p&gt;

&lt;p&gt;const (&lt;br&gt;
    APIURL      string = "&lt;a href="https://payments.relworx.com/api/mobile-money"&gt;https://payments.relworx.com/api/mobile-money&lt;/a&gt;"&lt;br&gt;
    ContentType string = "application/json"&lt;br&gt;
    AcceptType  string = "application/vnd.relworx.v2"&lt;br&gt;
)&lt;/p&gt;

&lt;p&gt;type WalletBalanceResponse struct {&lt;br&gt;
    Success bool   &lt;code&gt;json:"success"&lt;/code&gt;&lt;br&gt;
    Balance string &lt;code&gt;json:"balance"&lt;/code&gt;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;// CheckBalanceRoute defines the route for checking wallet balance&lt;br&gt;
func CheckBalanceRoute(r *gin.Engine) {&lt;br&gt;
    r.GET("/check-wallet-balance", CheckWalletBalanceHandler)&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;// CheckWalletBalance retrieves the wallet balance from the external API&lt;br&gt;
func CheckWalletBalance(accountNo, currency, apiToken string) (*WalletBalanceResponse, error) {&lt;br&gt;
    url := fmt.Sprintf("%s/check-wallet-balance?account_no=%s&amp;amp;currency=%s", APIURL, accountNo, currency)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;req, err := http.NewRequest("GET", url, nil)
if err != nil {
    return nil, fmt.Errorf("error creating request: %w", err) // Use %w to unwrap error
}

req.Header.Set("Accept", AcceptType)
req.Header.Set("Content-Type", ContentType)
req.Header.Set("Authorization", "Bearer "+apiToken)

client := &amp;amp;http.Client{}
resp, err := client.Do(req)
if err != nil {
    return nil, fmt.Errorf("error making request: %w", err) // Use %w to unwrap error
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
    return nil, fmt.Errorf("error reading response body: %w", err) // Use %w to unwrap error
}

var balanceResp WalletBalanceResponse
err = json.Unmarshal(body, &amp;amp;balanceResp)
if err != nil {
    return nil, fmt.Errorf("error decoding JSON response: %w", err) // Use %w to unwrap error
}

return &amp;amp;balanceResp, nil
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;// CheckWalletBalanceHandler handles requests to the check-wallet-balance endpoint&lt;br&gt;
func CheckWalletBalanceHandler(c *gin.Context) {&lt;br&gt;
    apiToken := os.Getenv("API_TOKEN")&lt;br&gt;
    if apiToken == "" {&lt;br&gt;
        c.JSON(http.StatusInternalServerError, gin.H{"error": "API_TOKEN environment variable not set"})&lt;br&gt;
        return&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;accountNo := c.Query("account_no")
if accountNo == "" {
    c.JSON(http.StatusBadRequest, gin.H{"error": "Missing account_no query parameter"})
    return
}

currency := c.Query("currency")
if currency == "" {
    c.JSON(http.StatusBadRequest, gin.H{"error": "Missing currency query parameter"})
    return
}

// Call CheckWalletBalance and handle potential errors
balanceResp, err := CheckWalletBalance(accountNo, currency, apiToken)
if err != nil {
    // Log the error for further investigation
    fmt.Println("Error checking wallet balance:", err)

    // Return a generic error message to the client, or consider providing more specific information depending on the error type.
    c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to check wallet balance"})
    return
}

// Respond with the balance information if successful
c.JSON(http.StatusOK, gin.H{"success": balanceResp.Success, "balance": balanceResp.Balance})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}package main&lt;/p&gt;

&lt;p&gt;import (&lt;br&gt;
    "fmt"&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/yourmodule/relworx/works/routes"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;)&lt;/p&gt;

&lt;p&gt;func main() {&lt;br&gt;
    // Create the Gin engine&lt;br&gt;
    router := gin.Default()&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;routes.ValidateNumberRoute()
routes.SendPaymentRoute(router)
routes.RequestMobilePaymentRoute()
routes.CheckBalanceRoute(router)

if err := godotenv.Load(); err != nil {
    fmt.Println("Error loading .env file")
    return
}
// Start the server with the router
if err := router.Run(":8001"); err != nil {
    panic(err)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
" here is my models file for the same"package models&lt;/p&gt;

&lt;p&gt;type CheckWalletBalanceRequest struct {&lt;br&gt;
    AccountNo string &lt;code&gt;json:"account_no" binding:"required"&lt;/code&gt;&lt;br&gt;
    Currency  string &lt;code&gt;json:"currency" binding:"required"&lt;/code&gt;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;type CheckWalletBalanceResponse struct {&lt;br&gt;
    Success bool   &lt;code&gt;json:"success"&lt;/code&gt;&lt;br&gt;
    Balance string &lt;code&gt;json:"balance"&lt;/code&gt;&lt;br&gt;
}&lt;br&gt;
" some one help please&lt;br&gt;
and here is my main.go file "&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
