Documentation
¶
Overview ¶
Package warden provides a client SDK for interacting with Warden API.
Index ¶
- Constants
- type AllowListUser
- type Cache
- type Client
- func (c *Client) CheckUserInList(ctx context.Context, phone, mail string) bool
- func (c *Client) ClearCache()
- func (c *Client) GetUserByIdentifier(ctx context.Context, phone, mail, userID string) (*AllowListUser, error)
- func (c *Client) GetUsers(ctx context.Context) ([]AllowListUser, error)
- func (c *Client) GetUsersPaginated(ctx context.Context, page, pageSize int) (*PaginatedResponse, error)
- type Error
- type Logger
- type LogrusAdapter
- func (l *LogrusAdapter) Debug(msg string)
- func (l *LogrusAdapter) Debugf(format string, args ...interface{})
- func (l *LogrusAdapter) Error(msg string)
- func (l *LogrusAdapter) Errorf(format string, args ...interface{})
- func (l *LogrusAdapter) Info(msg string)
- func (l *LogrusAdapter) Infof(format string, args ...interface{})
- func (l *LogrusAdapter) Warn(msg string)
- func (l *LogrusAdapter) Warnf(format string, args ...interface{})
- type NoOpLogger
- func (n *NoOpLogger) Debug(msg string)
- func (n *NoOpLogger) Debugf(format string, args ...interface{})
- func (n *NoOpLogger) Error(msg string)
- func (n *NoOpLogger) Errorf(format string, args ...interface{})
- func (n *NoOpLogger) Info(msg string)
- func (n *NoOpLogger) Infof(format string, args ...interface{})
- func (n *NoOpLogger) Warn(msg string)
- func (n *NoOpLogger) Warnf(format string, args ...interface{})
- type Options
- func (o *Options) Validate() error
- func (o *Options) WithAPIKey(key string) *Options
- func (o *Options) WithBaseURL(url string) *Options
- func (o *Options) WithCacheTTL(ttl time.Duration) *Options
- func (o *Options) WithLogger(logger Logger) *Options
- func (o *Options) WithTimeout(timeout time.Duration) *Options
- type PaginatedResponse
- type PaginationInfo
Constants ¶
const ( ErrCodeInvalidConfig = "INVALID_CONFIG" ErrCodeRequestFailed = "REQUEST_FAILED" ErrCodeInvalidResponse = "INVALID_RESPONSE" ErrCodeNotFound = "NOT_FOUND" ErrCodeServerError = "SERVER_ERROR" )
Predefined error codes
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AllowListUser ¶
type AllowListUser struct {
Phone string `json:"phone"` // User phone number
Mail string `json:"mail"` // User email address
UserID string `json:"user_id"` // User unique identifier (optional, auto-generated if not provided)
Status string `json:"status"` // User status (e.g., "active", "inactive", "suspended")
Scope []string `json:"scope"` // User permission scope (optional)
Role string `json:"role"` // User role (optional)
}
AllowListUser represents a user in the allow list.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache provides thread-safe caching for user list.
func (*Cache) Get ¶
func (c *Cache) Get() []AllowListUser
Get returns the cached user list if it's still valid, nil otherwise.
func (*Cache) Set ¶
func (c *Cache) Set(users []AllowListUser)
Set stores the user list in cache with expiration.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Warden API client.
func (*Client) CheckUserInList ¶
CheckUserInList checks if a user (by phone or mail) is in the allow list. Returns false if the user is not found, or if there's an error fetching the user list.
func (*Client) GetUserByIdentifier ¶
func (c *Client) GetUserByIdentifier(ctx context.Context, phone, mail, userID string) (*AllowListUser, error)
GetUserByIdentifier fetches a single user by phone, mail, or user_id. Only one identifier should be provided.
func (*Client) GetUsers ¶
func (c *Client) GetUsers(ctx context.Context) ([]AllowListUser, error)
GetUsers fetches the user list from Warden API. If pagination parameters are not provided, returns all users.
func (*Client) GetUsersPaginated ¶
func (c *Client) GetUsersPaginated(ctx context.Context, page, pageSize int) (*PaginatedResponse, error)
GetUsersPaginated fetches a paginated user list from Warden API.
type Error ¶
type Error struct {
Code string // Error code
Message string // Error message
Err error // Original error (if any)
}
Error represents an error that occurred in the SDK.
type Logger ¶
type Logger interface {
Debug(msg string)
Debugf(format string, args ...interface{})
Info(msg string)
Infof(format string, args ...interface{})
Warn(msg string)
Warnf(format string, args ...interface{})
Error(msg string)
Errorf(format string, args ...interface{})
}
Logger defines the interface for logging operations. This allows the SDK to work with different logging libraries (e.g., zerolog, logrus, standard log).
type LogrusAdapter ¶
type LogrusAdapter struct {
// contains filtered or unexported fields
}
LogrusAdapter adapts logrus.Logger to the SDK Logger interface.
func NewLogrusAdapter ¶
func NewLogrusAdapter(logger *logrus.Logger) *LogrusAdapter
NewLogrusAdapter creates a new LogrusAdapter.
func (*LogrusAdapter) Debug ¶
func (l *LogrusAdapter) Debug(msg string)
Debug logs a debug message using logrus.
func (*LogrusAdapter) Debugf ¶
func (l *LogrusAdapter) Debugf(format string, args ...interface{})
Debugf logs a formatted debug message using logrus.
func (*LogrusAdapter) Error ¶
func (l *LogrusAdapter) Error(msg string)
Error logs an error message using logrus.
func (*LogrusAdapter) Errorf ¶
func (l *LogrusAdapter) Errorf(format string, args ...interface{})
Errorf logs a formatted error message using logrus.
func (*LogrusAdapter) Info ¶
func (l *LogrusAdapter) Info(msg string)
Info logs an info message using logrus.
func (*LogrusAdapter) Infof ¶
func (l *LogrusAdapter) Infof(format string, args ...interface{})
Infof logs a formatted info message using logrus.
func (*LogrusAdapter) Warn ¶
func (l *LogrusAdapter) Warn(msg string)
Warn logs a warning message using logrus.
func (*LogrusAdapter) Warnf ¶
func (l *LogrusAdapter) Warnf(format string, args ...interface{})
Warnf logs a formatted warning message using logrus.
type NoOpLogger ¶
type NoOpLogger struct{}
NoOpLogger is a no-op implementation of Logger that discards all log messages. This is used as the default logger when no logger is provided.
func (*NoOpLogger) Debugf ¶
func (n *NoOpLogger) Debugf(format string, args ...interface{})
Debugf discards formatted debug messages.
func (*NoOpLogger) Errorf ¶
func (n *NoOpLogger) Errorf(format string, args ...interface{})
Errorf discards formatted error messages.
func (*NoOpLogger) Infof ¶
func (n *NoOpLogger) Infof(format string, args ...interface{})
Infof discards formatted info messages.
func (*NoOpLogger) Warnf ¶
func (n *NoOpLogger) Warnf(format string, args ...interface{})
Warnf discards formatted warning messages.
type Options ¶
type Options struct {
BaseURL string // Warden service address (required)
APIKey string // API Key (optional)
Timeout time.Duration // HTTP request timeout (default 10s)
CacheTTL time.Duration // Cache TTL (default 5 minutes)
Logger Logger // Logger interface (optional, defaults to NoOpLogger)
}
Options contains configuration options for the Warden SDK client.
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions returns default options with sensible defaults.
func (*Options) WithAPIKey ¶
WithAPIKey sets the API key for authentication.
func (*Options) WithBaseURL ¶
WithBaseURL sets the base URL for the Warden service.
func (*Options) WithCacheTTL ¶
WithCacheTTL sets the cache TTL.
func (*Options) WithLogger ¶
WithLogger sets the logger implementation.
type PaginatedResponse ¶
type PaginatedResponse struct {
Data []AllowListUser `json:"data"`
Pagination PaginationInfo `json:"pagination"`
}
PaginatedResponse represents a paginated response from the Warden API.
type PaginationInfo ¶
type PaginationInfo struct {
Page int `json:"page"` // Current page number (starts from 1)
PageSize int `json:"page_size"` // Page size
Total int `json:"total"` // Total number of records
TotalPages int `json:"total_pages"` // Total number of pages
}
PaginationInfo contains pagination metadata.