Documentation
¶
Index ¶
- Constants
- type BaseClient
- func (c *BaseClient) BaseURL() string
- func (c *BaseClient) Delete(ctx context.Context, path string, result any) *errors.Error
- func (c *BaseClient) DeleteWithHeaders(ctx context.Context, path string, result any, headers map[string]string) *errors.Error
- func (c *BaseClient) Get(ctx context.Context, path string, result any) *errors.Error
- func (c *BaseClient) GetWithHeaders(ctx context.Context, path string, result any, headers map[string]string) *errors.Error
- func (c *BaseClient) Post(ctx context.Context, path string, body, result any) *errors.Error
- func (c *BaseClient) PostWithHeaders(ctx context.Context, path string, body, result any, headers map[string]string) *errors.Error
- func (c *BaseClient) Put(ctx context.Context, path string, body, result any) *errors.Error
- func (c *BaseClient) PutWithHeaders(ctx context.Context, path string, body, result any, headers map[string]string) *errors.Error
- func (c *BaseClient) SetAuthToken(token string)
- func (c *BaseClient) SetInternalSecret(secret string)
- type EnvelopeError
- type NotificationChannel
- type NotificationClient
- func (c *NotificationClient) SendKYCStatusNotification(ctx context.Context, ...) *errors.Error
- func (c *NotificationClient) SendNotification(ctx context.Context, req *SendNotificationRequest) (*SendNotificationResponse, *errors.Error)
- func (c *NotificationClient) SendNotificationAsync(req *SendNotificationRequest, serviceName string)
- func (c *NotificationClient) SendTransactionNotification(ctx context.Context, ...) *errors.Error
- func (c *NotificationClient) SendWalletNotification(ctx context.Context, ...) *errors.Error
- func (c *NotificationClient) SendWelcomeNotification(ctx context.Context, ...) *errors.Error
- type NotificationPriority
- type NotificationType
- type SendNotificationRequest
- type SendNotificationResponse
Constants ¶
const ( DefaultTimeout = 10 * time.Second ShortTimeout = 5 * time.Second LongTimeout = 30 * time.Second )
Default timeouts for service clients
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseClient ¶
type BaseClient struct {
// contains filtered or unexported fields
}
BaseClient provides common HTTP functionality for service-to-service communication. Embed this in service-specific clients to get consistent error handling, timeouts, and response envelope parsing.
func NewBaseClient ¶
func NewBaseClient(baseURL string, timeout time.Duration) *BaseClient
NewBaseClient creates a new base client with the specified timeout.
func NewBaseClientWithHeaders ¶
func NewBaseClientWithHeaders(baseURL string, timeout time.Duration, headers map[string]string) *BaseClient
NewBaseClientWithHeaders creates a new base client with default headers. These headers will be applied to all requests made by this client.
func NewInternalClient ¶
func NewInternalClient(baseURL string, timeout time.Duration, internalSecret string) *BaseClient
NewInternalClient creates a base client configured for internal service-to-service calls. The secret is sent as X-Internal-Secret header and validated by InternalAuth middleware.
func (*BaseClient) BaseURL ¶
func (c *BaseClient) BaseURL() string
BaseURL returns the base URL for building endpoint paths.
func (*BaseClient) DeleteWithHeaders ¶
func (c *BaseClient) DeleteWithHeaders(ctx context.Context, path string, result any, headers map[string]string) *errors.Error
DeleteWithHeaders performs a DELETE request with additional headers.
func (*BaseClient) Get ¶
Get performs a GET request and parses the envelope response into result. The result parameter should be a pointer to the expected data type.
func (*BaseClient) GetWithHeaders ¶
func (c *BaseClient) GetWithHeaders(ctx context.Context, path string, result any, headers map[string]string) *errors.Error
GetWithHeaders performs a GET request with additional headers.
func (*BaseClient) Post ¶
Post performs a POST request with JSON body and parses the envelope response. The body parameter will be marshaled to JSON. Pass nil for empty body. The result parameter should be a pointer to the expected data type, or nil if no response data expected.
func (*BaseClient) PostWithHeaders ¶
func (c *BaseClient) PostWithHeaders(ctx context.Context, path string, body, result any, headers map[string]string) *errors.Error
PostWithHeaders performs a POST request with additional headers.
func (*BaseClient) Put ¶
Put performs a PUT request with JSON body and parses the envelope response.
func (*BaseClient) PutWithHeaders ¶
func (c *BaseClient) PutWithHeaders(ctx context.Context, path string, body, result any, headers map[string]string) *errors.Error
PutWithHeaders performs a PUT request with additional headers.
func (*BaseClient) SetAuthToken ¶
func (c *BaseClient) SetAuthToken(token string)
SetAuthToken sets a Bearer token for all requests. This is a convenience method for the common auth pattern.
func (*BaseClient) SetInternalSecret ¶
func (c *BaseClient) SetInternalSecret(secret string)
SetInternalSecret sets the internal service secret for service-to-service calls. This header is validated by the InternalAuth middleware on receiving services.
type EnvelopeError ¶
EnvelopeError represents the error field in API responses. Supports both string and object formats.
func (*EnvelopeError) UnmarshalJSON ¶
func (e *EnvelopeError) UnmarshalJSON(data []byte) error
UnmarshalJSON handles both string and object error formats.
type NotificationChannel ¶
type NotificationChannel string
NotificationChannel represents the delivery channel for a notification.
const ( NotificationChannelSMS NotificationChannel = "sms" NotificationChannelEmail NotificationChannel = "email" NotificationChannelPush NotificationChannel = "push" NotificationChannelInApp NotificationChannel = "in_app" )
type NotificationClient ¶
type NotificationClient struct {
*BaseClient
// contains filtered or unexported fields
}
NotificationClient handles communication with the notification service.
func NewNotificationClient ¶
func NewNotificationClient(baseURL string) *NotificationClient
NewNotificationClient creates a new notification client.
func (*NotificationClient) SendKYCStatusNotification ¶
func (c *NotificationClient) SendKYCStatusNotification(ctx context.Context, userID, email, phone, fullName, status, reason, templateID, sourceSvc string) *errors.Error
SendKYCStatusNotification sends a KYC status update notification.
func (*NotificationClient) SendNotification ¶
func (c *NotificationClient) SendNotification(ctx context.Context, req *SendNotificationRequest) (*SendNotificationResponse, *errors.Error)
SendNotification sends a notification via the notification service.
func (*NotificationClient) SendNotificationAsync ¶
func (c *NotificationClient) SendNotificationAsync(req *SendNotificationRequest, serviceName string)
SendNotificationAsync sends a notification asynchronously (fire and forget). It logs errors but does not block or return them.
func (*NotificationClient) SendTransactionNotification ¶
func (c *NotificationClient) SendTransactionNotification(ctx context.Context, userID, email, phone, transactionID, transactionType, amount, currency, templateID, sourceSvc string, priority NotificationPriority) *errors.Error
SendTransactionNotification sends a transaction-related notification.
func (*NotificationClient) SendWalletNotification ¶
func (c *NotificationClient) SendWalletNotification(ctx context.Context, userID, email, walletID, walletType, currency, templateID, sourceSvc string, notifType NotificationType) *errors.Error
SendWalletNotification sends a wallet-related notification.
func (*NotificationClient) SendWelcomeNotification ¶
func (c *NotificationClient) SendWelcomeNotification(ctx context.Context, userID, email, phone, fullName, templateID, sourceSvc string) *errors.Error
SendWelcomeNotification sends a welcome notification to a new user.
type NotificationPriority ¶
type NotificationPriority string
NotificationPriority represents the urgency of a notification.
const ( NotificationPriorityCritical NotificationPriority = "critical" NotificationPriorityHigh NotificationPriority = "high" NotificationPriorityNormal NotificationPriority = "normal" NotificationPriorityLow NotificationPriority = "low" )
type NotificationType ¶
type NotificationType string
NotificationType represents the category of notification.
const ( NotificationTypeWelcome NotificationType = "welcome" NotificationTypeKYCStatus NotificationType = "kyc_status" NotificationTypeWalletCreated NotificationType = "wallet_created" NotificationTypeWalletActivated NotificationType = "wallet_activated" NotificationTypeTransactionAlert NotificationType = "transaction_alert" NotificationTypeSecurityAlert NotificationType = "security_alert" NotificationTypeOTP NotificationType = "otp" NotificationTypeMarketing NotificationType = "marketing" NotificationTypeSystemAlert NotificationType = "system_alert" )
type SendNotificationRequest ¶
type SendNotificationRequest struct {
UserID *string `json:"user_id,omitempty"`
Recipient string `json:"recipient"`
Channel NotificationChannel `json:"channel"`
Type NotificationType `json:"type"`
Priority NotificationPriority `json:"priority"`
TemplateID string `json:"template_id"`
Variables map[string]any `json:"variables,omitempty"`
CorrelationID *string `json:"correlation_id,omitempty"`
SourceService string `json:"source_service"`
Metadata map[string]any `json:"metadata,omitempty"`
}
SendNotificationRequest represents a request to send a notification.