108629278a
- Added a new notification service to handle various notification types (email, SMS, push, OTP). - Implemented configuration for the notification service, allowing customization via environment variables. - Updated user and customer services to utilize the notification service for sending welcome emails and status updates. - Introduced a builder pattern for constructing notification requests, enhancing usability and flexibility. - Enhanced error handling and logging for notification operations, ensuring robust service integration. - Updated documentation to include usage examples and configuration details for the new notification SDK.
57 lines
1.6 KiB
Go
57 lines
1.6 KiB
Go
package notification
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// Config holds the notification service configuration
|
|
type Config struct {
|
|
BaseURL string ``
|
|
RetryAttempts int ``
|
|
Timeout time.Duration ``
|
|
RetryDelay time.Duration ``
|
|
EnableLogging bool ``
|
|
UserAgent string ``
|
|
}
|
|
|
|
// DefaultConfig returns default configuration for notification service
|
|
func DefaultConfig() *Config {
|
|
return &Config{
|
|
BaseURL: "http://127.0.0.1:9095",
|
|
Timeout: 30 * time.Second,
|
|
RetryAttempts: 3,
|
|
RetryDelay: 2 * time.Second,
|
|
EnableLogging: true,
|
|
UserAgent: "TenderManagement-NotificationSDK/1.0",
|
|
}
|
|
}
|
|
|
|
// NewConfig creates a new configuration for notification service
|
|
func NewConfig(baseURL string, timeout time.Duration, retryAttempts int, retryDelay time.Duration, enableLogging bool, userAgent string) *Config {
|
|
return &Config{
|
|
BaseURL: baseURL,
|
|
Timeout: timeout,
|
|
RetryAttempts: retryAttempts,
|
|
RetryDelay: retryDelay,
|
|
EnableLogging: enableLogging,
|
|
UserAgent: userAgent,
|
|
}
|
|
}
|
|
|
|
// Validate validates the configuration
|
|
func (c *Config) Validate() error {
|
|
if c.BaseURL == "" {
|
|
return ErrInvalidConfig{Field: "BaseURL", Message: "base URL cannot be empty"}
|
|
}
|
|
if c.Timeout <= 0 {
|
|
return ErrInvalidConfig{Field: "Timeout", Message: "timeout must be positive"}
|
|
}
|
|
if c.RetryAttempts < 0 {
|
|
return ErrInvalidConfig{Field: "RetryAttempts", Message: "retry attempts cannot be negative"}
|
|
}
|
|
if c.RetryDelay < 0 {
|
|
return ErrInvalidConfig{Field: "RetryDelay", Message: "retry delay cannot be negative"}
|
|
}
|
|
return nil
|
|
}
|