Compare commits

...

3 Commits

Author SHA1 Message Date
68d1628546
replace - with: Not provided 2024-11-08 17:19:41 +03:00
f4f95b3292
add some spacing 2024-11-08 17:15:27 +03:00
fc8915ea33
add http logging 2024-11-07 16:35:58 +03:00
3 changed files with 41 additions and 17 deletions

View File

@ -1177,7 +1177,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FIRST_NAME)
if err != nil {
if db.IsNotFound(err) {
res.Content = "-"
res.Content = "Not provided"
break
}
return res, err
@ -1187,7 +1187,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_FAMILY_NAME)
if err != nil {
if db.IsNotFound(err) {
res.Content = "-"
res.Content = "Not provided"
break
}
return res, err
@ -1198,7 +1198,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_GENDER)
if err != nil {
if db.IsNotFound(err) {
res.Content = "-"
res.Content = "Not provided"
break
}
return res, err
@ -1208,7 +1208,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_YOB)
if err != nil {
if db.IsNotFound(err) {
res.Content = "-"
res.Content = "Not provided"
break
}
return res, err
@ -1219,7 +1219,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_LOCATION)
if err != nil {
if db.IsNotFound(err) {
res.Content = "-"
res.Content = "Not provided"
break
}
return res, err
@ -1229,7 +1229,7 @@ func (h *Handlers) GetCurrentProfileInfo(ctx context.Context, sym string, input
profileInfo, err = store.ReadEntry(ctx, sessionId, common.DATA_OFFERINGS)
if err != nil {
if db.IsNotFound(err) {
res.Content = "-"
res.Content = "Not provided"
break
}
return res, err

View File

@ -1,20 +1,26 @@
package remote
import (
"bytes"
"context"
"encoding/json"
"errors"
"io"
"log"
"net/http"
"net/url"
"os"
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
"github.com/grassrootseconomics/eth-custodial/pkg/api"
"git.grassecon.net/urdt/ussd/config"
"git.grassecon.net/urdt/ussd/models"
"github.com/grassrootseconomics/eth-custodial/pkg/api"
dataserviceapi "github.com/grassrootseconomics/ussd-data-service/pkg/api"
)
var (
DebugLogger = log.New(os.Stdout, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile)
InfoLogger = log.New(os.Stdout, "INFO: ", log.Ldate|log.Ltime)
ErrorLogger = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
)
type AccountServiceInterface interface {
@ -79,7 +85,6 @@ func (as *AccountService) CheckBalance(ctx context.Context, publicKey string) (*
return &balanceResult, err
}
// CreateAccount creates a new account in the custodial system.
// Returns:
// - *models.AccountResponse: A pointer to an AccountResponse struct containing the details of the created account.
@ -126,7 +131,6 @@ func (as *AccountService) FetchVouchers(ctx context.Context, publicKey string) (
return r, nil
}
// FetchTransactions retrieves the last 10 transactions for a given public key from the data indexer API endpoint
// Parameters:
// - publicKey: The public key associated with the account.
@ -151,7 +155,6 @@ func (as *AccountService) FetchTransactions(ctx context.Context, publicKey strin
return r, nil
}
// VoucherData retrieves voucher metadata from the data indexer API endpoint.
// Parameters:
// - address: The voucher address.
@ -184,6 +187,7 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons
}
defer resp.Body.Close()
InfoLogger.Printf("Received response for %s: Status Code: %d | Content-Type: %s", req.URL, resp.StatusCode, resp.Header.Get("Content-Type"))
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
@ -214,10 +218,30 @@ func doRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKRespons
func doCustodialRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
req.Header.Set("X-GE-KEY", config.CustodialAPIKey)
logRequestDetails(req, config.CustodialAPIKey)
return doRequest(ctx, req, rcpt)
}
func doDataRequest(ctx context.Context, req *http.Request, rcpt any) (*api.OKResponse, error) {
req.Header.Set("X-GE-KEY", config.DataAPIKey)
logRequestDetails(req, config.CustodialAPIKey)
return doRequest(ctx, req, rcpt)
}
func logRequestDetails(req *http.Request, apiKey string) {
var bodyBytes []byte
contentType := req.Header.Get("Content-Type")
if req.Body != nil {
bodyBytes, err := io.ReadAll(req.Body)
if err != nil {
ErrorLogger.Printf("Error reading request body: %s", err)
return
}
req.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
} else {
bodyBytes = []byte("-")
}
InfoLogger.Printf("URL: %s | Content-Type: %s | Method: %s| Request Body: %s", req.URL, contentType, req.Method, string(bodyBytes))
}

View File

@ -1,2 +1,2 @@
Current familyname: {{.get_current_profile_info}}
Current family name: {{.get_current_profile_info}}
Enter family name: