Documentation
¶
Index ¶
- Variables
- func Base64Decode(data string) (string, error)
- func Base64Encode(data string) string
- func CapitalizeFirst(text string) string
- func CreateWebhookSignature(payload, secret string) string
- func FormatBytes(bytes int64) string
- func FormatDuration(seconds int64) string
- func FormatTimestamp(timestamp int64) string
- func GenerateLicenseKey() string
- func GenerateUUID() string
- func GetCurrentDate() string
- func GetCurrentTimestamp() int64
- func IsValidJSON(jsonString string) bool
- func IsValidURL(urlString string) bool
- func JSONDeserialize(data string, obj interface{}) error
- func JSONSerialize(obj interface{}) (string, error)
- func MD5(data string) string
- func ParseTimestamp(timestamp string) (int64, error)
- func RetryWithBackoff(fn func() error, maxRetries int, initialDelay time.Duration) error
- func SHA1(data string) string
- func SHA256(data string) string
- func SanitizeInput(input string) string
- func SanitizeMetadata(metadata map[string]interface{}) map[string]interface{}
- func Sleep(duration time.Duration)
- func Slugify(text string) string
- func ToPascalCase(text string) string
- func ToSnakeCase(text string) string
- func TruncateString(text string, maxLength int) string
- func URLDecode(s string) (string, error)
- func URLEncode(s string) string
- func ValidateAmount(amount float64) bool
- func ValidateCurrency(currency string) bool
- func ValidateDateRange(startDate, endDate string) error
- func ValidateEmail(email string) bool
- func ValidateLicenseKey(licenseKey string) bool
- func ValidateNotEmpty(value, fieldName string) error
- func ValidatePagination(page, limit int) (int, int)
- func ValidatePositive(value float64, fieldName string) error
- func ValidateRange(value, min, max float64, fieldName string) error
- func ValidateUUID(uuid string) bool
- func VerifyWebhookSignature(payload, signature, secret string) bool
- type CreateLicenseRequest
- type CreateProductRequest
- type CreateUserRequest
- type CreateWebhookRequest
- type HealthResponse
- type License
- type LicenseChainClient
- func (c *LicenseChainClient) CreateLicense(req CreateLicenseRequest) (*License, error)
- func (c *LicenseChainClient) GetLicense(licenseID string) (*License, error)
- func (c *LicenseChainClient) Health() (*HealthResponse, error)
- func (c *LicenseChainClient) Ping() (*PingResponse, error)
- func (c *LicenseChainClient) ValidateLicense(licenseKey string) (bool, error)
- type LicenseChainError
- func NewAuthenticationError(message string) *LicenseChainError
- func NewHTTPError(statusCode int, message string) *LicenseChainError
- func NewNotFoundError(message string) *LicenseChainError
- func NewRateLimitError(message string) *LicenseChainError
- func NewServerError(message string) *LicenseChainError
- func NewValidationError(message string) *LicenseChainError
- type LicenseListResponse
- type LicenseStats
- type PingResponse
- type Product
- type ProductListResponse
- type ProductStats
- type UpdateLicenseRequest
- type UpdateProductRequest
- type UpdateUserRequest
- type UpdateWebhookRequest
- type User
- type UserListResponse
- type UserStats
- type Webhook
- type WebhookHandler
- func (wh *WebhookHandler) ProcessEvent(eventData map[string]interface{}) error
- func (wh *WebhookHandler) VerifySignature(payload, signature string) bool
- func (wh *WebhookHandler) VerifyTimestamp(timestamp string) error
- func (wh *WebhookHandler) VerifyWebhook(payload, signature, timestamp string) error
- type WebhookListResponse
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidAPIKey = &LicenseChainError{Type: "invalid_api_key", Message: "Invalid API key provided"} ErrInvalidURL = &LicenseChainError{Type: "invalid_url", Message: "Invalid URL"} ErrInvalidResponse = &LicenseChainError{Type: "invalid_response", Message: "Invalid response from server"} ErrNetworkError = &LicenseChainError{Type: "network_error", Message: "Network error occurred"} ErrValidationError = &LicenseChainError{Type: "validation_error", Message: "Validation error"} ErrAuthenticationError = &LicenseChainError{Type: "authentication_error", Message: "Authentication error"} ErrNotFoundError = &LicenseChainError{Type: "not_found_error", Message: "Resource not found"} ErrRateLimitError = &LicenseChainError{Type: "rate_limit_error", Message: "Rate limit exceeded"} ErrServerError = &LicenseChainError{Type: "server_error", Message: "Server error"} ErrUnknownError = &LicenseChainError{Type: "unknown_error", Message: "Unknown error occurred"} )
Error types
var WebhookEvents = struct { LicenseCreated string LicenseUpdated string LicenseRevoked string LicenseExpired string UserCreated string UserUpdated string UserDeleted string ProductCreated string ProductUpdated string ProductDeleted string PaymentCompleted string PaymentFailed string PaymentRefunded string }{ LicenseCreated: "license.created", LicenseUpdated: "license.updated", LicenseRevoked: "license.revoked", LicenseExpired: "license.expired", UserCreated: "user.created", UserUpdated: "user.updated", UserDeleted: "user.deleted", ProductCreated: "product.created", ProductUpdated: "product.updated", ProductDeleted: "product.deleted", PaymentCompleted: "payment.completed", PaymentFailed: "payment.failed", PaymentRefunded: "payment.refunded", }
WebhookEvents contains webhook event type constants
Functions ¶
func Base64Decode ¶
Base64Decode decodes a base64 string
func CapitalizeFirst ¶
CapitalizeFirst capitalizes the first letter of a string
func CreateWebhookSignature ¶
CreateWebhookSignature creates a webhook signature
func FormatBytes ¶
FormatBytes formats bytes into human readable format
func FormatDuration ¶
FormatDuration formats duration in seconds
func FormatTimestamp ¶
FormatTimestamp formats a timestamp
func GenerateLicenseKey ¶
func GenerateLicenseKey() string
GenerateLicenseKey generates a random license key
func GetCurrentDate ¶
func GetCurrentDate() string
GetCurrentDate returns the current date as ISO string
func GetCurrentTimestamp ¶
func GetCurrentTimestamp() int64
GetCurrentTimestamp returns the current timestamp
func IsValidJSON ¶
IsValidJSON checks if a string is valid JSON
func IsValidURL ¶
IsValidURL checks if a string is a valid URL
func JSONDeserialize ¶
JSONDeserialize deserializes JSON to an object
func JSONSerialize ¶
JSONSerialize serializes an object to JSON
func ParseTimestamp ¶
ParseTimestamp parses a timestamp string
func RetryWithBackoff ¶
RetryWithBackoff retries a function with exponential backoff
func SanitizeMetadata ¶
SanitizeMetadata sanitizes metadata
func ToPascalCase ¶
ToPascalCase converts a string to PascalCase
func TruncateString ¶
TruncateString truncates a string to a maximum length
func ValidateCurrency ¶
ValidateCurrency validates a currency code
func ValidateDateRange ¶
ValidateDateRange validates a date range
func ValidateLicenseKey ¶
ValidateLicenseKey validates a license key format
func ValidateNotEmpty ¶
ValidateNotEmpty validates that a string is not empty
func ValidatePagination ¶
ValidatePagination validates pagination parameters
func ValidatePositive ¶
ValidatePositive validates that a number is positive
func ValidateRange ¶
ValidateRange validates that a number is within a range
func VerifyWebhookSignature ¶
VerifyWebhookSignature verifies a webhook signature
Types ¶
type CreateLicenseRequest ¶
type CreateLicenseRequest struct {
UserID string `json:"user_id"`
ProductID string `json:"product_id"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
CreateLicenseRequest represents a request to create a license
type CreateProductRequest ¶
type CreateProductRequest struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Price float64 `json:"price"`
Currency string `json:"currency"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
CreateProductRequest represents a request to create a product
type CreateUserRequest ¶
type CreateUserRequest struct {
Email string `json:"email"`
Name string `json:"name"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
CreateUserRequest represents a request to create a user
type CreateWebhookRequest ¶
type CreateWebhookRequest struct {
URL string `json:"url"`
Events []string `json:"events"`
Secret string `json:"secret,omitempty"`
}
CreateWebhookRequest represents a request to create a webhook
type HealthResponse ¶
type HealthResponse struct {
Status string `json:"status"`
Timestamp string `json:"timestamp"`
Version string `json:"version"`
}
HealthResponse represents a health check response
type License ¶
type License struct {
ID string `json:"id"`
UserID string `json:"user_id"`
ProductID string `json:"product_id"`
LicenseKey string `json:"license_key"`
Status string `json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
License represents a license in the LicenseChain system
type LicenseChainClient ¶
type LicenseChainClient struct {
// contains filtered or unexported fields
}
LicenseChainClient represents the main client for the LicenseChain API
func CreateClient ¶
func CreateClient(apiKey string, baseURL ...string) *LicenseChainClient
CreateClient creates a new client with default settings
func FromEnvironment ¶
func FromEnvironment() *LicenseChainClient
FromEnvironment creates a client from environment variables
func NewClient ¶
func NewClient(apiKey, baseURL string, timeout time.Duration, retries int) *LicenseChainClient
NewClient creates a new LicenseChain client
func (*LicenseChainClient) CreateLicense ¶
func (c *LicenseChainClient) CreateLicense(req CreateLicenseRequest) (*License, error)
CreateLicense creates a new license
func (*LicenseChainClient) GetLicense ¶
func (c *LicenseChainClient) GetLicense(licenseID string) (*License, error)
GetLicense retrieves a license by ID
func (*LicenseChainClient) Health ¶
func (c *LicenseChainClient) Health() (*HealthResponse, error)
Health checks the API health
func (*LicenseChainClient) Ping ¶
func (c *LicenseChainClient) Ping() (*PingResponse, error)
Ping pings the API
func (*LicenseChainClient) ValidateLicense ¶
func (c *LicenseChainClient) ValidateLicense(licenseKey string) (bool, error)
ValidateLicense validates a license key
type LicenseChainError ¶
type LicenseChainError struct {
Type string `json:"type"`
Message string `json:"message"`
Code int `json:"code,omitempty"`
}
LicenseChainError represents an error from the LicenseChain API
func NewAuthenticationError ¶
func NewAuthenticationError(message string) *LicenseChainError
NewAuthenticationError creates a new authentication error
func NewHTTPError ¶
func NewHTTPError(statusCode int, message string) *LicenseChainError
NewHTTPError creates a new HTTP error
func NewNotFoundError ¶
func NewNotFoundError(message string) *LicenseChainError
NewNotFoundError creates a new not found error
func NewRateLimitError ¶
func NewRateLimitError(message string) *LicenseChainError
NewRateLimitError creates a new rate limit error
func NewServerError ¶
func NewServerError(message string) *LicenseChainError
NewServerError creates a new server error
func NewValidationError ¶
func NewValidationError(message string) *LicenseChainError
NewValidationError creates a new validation error
func (*LicenseChainError) Error ¶
func (e *LicenseChainError) Error() string
type LicenseListResponse ¶
type LicenseListResponse struct {
Data []License `json:"data"`
Total int `json:"total"`
Page int `json:"page"`
Limit int `json:"limit"`
}
LicenseListResponse represents a paginated list of licenses
type LicenseStats ¶
type LicenseStats struct {
Total int `json:"total"`
Active int `json:"active"`
Expired int `json:"expired"`
Revoked int `json:"revoked"`
Revenue float64 `json:"revenue"`
}
LicenseStats represents license statistics
type PingResponse ¶
PingResponse represents a ping response
type Product ¶
type Product struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
Price float64 `json:"price"`
Currency string `json:"currency"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Product represents a product in the LicenseChain system
type ProductListResponse ¶
type ProductListResponse struct {
Data []Product `json:"data"`
Total int `json:"total"`
Page int `json:"page"`
Limit int `json:"limit"`
}
ProductListResponse represents a paginated list of products
type ProductStats ¶
type ProductStats struct {
Total int `json:"total"`
Active int `json:"active"`
Revenue float64 `json:"revenue"`
}
ProductStats represents product statistics
type UpdateLicenseRequest ¶
type UpdateLicenseRequest struct {
Status string `json:"status,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
UpdateLicenseRequest represents a request to update a license
type UpdateProductRequest ¶
type UpdateProductRequest struct {
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Price float64 `json:"price,omitempty"`
Currency string `json:"currency,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
UpdateProductRequest represents a request to update a product
type UpdateUserRequest ¶
type UpdateUserRequest struct {
Email string `json:"email,omitempty"`
Name string `json:"name,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
UpdateUserRequest represents a request to update a user
type UpdateWebhookRequest ¶
type UpdateWebhookRequest struct {
URL string `json:"url,omitempty"`
Events []string `json:"events,omitempty"`
Secret string `json:"secret,omitempty"`
}
UpdateWebhookRequest represents a request to update a webhook
type User ¶
type User struct {
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
User represents a user in the LicenseChain system
type UserListResponse ¶
type UserListResponse struct {
Data []User `json:"data"`
Total int `json:"total"`
Page int `json:"page"`
Limit int `json:"limit"`
}
UserListResponse represents a paginated list of users
type UserStats ¶
type UserStats struct {
Total int `json:"total"`
Active int `json:"active"`
Inactive int `json:"inactive"`
}
UserStats represents user statistics
type Webhook ¶
type Webhook struct {
ID string `json:"id"`
URL string `json:"url"`
Events []string `json:"events"`
Secret string `json:"secret,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Webhook represents a webhook in the LicenseChain system
type WebhookHandler ¶
type WebhookHandler struct {
// contains filtered or unexported fields
}
WebhookHandler handles webhook events
func NewWebhookHandler ¶
func NewWebhookHandler(secret string, tolerance int64) *WebhookHandler
NewWebhookHandler creates a new webhook handler
func (*WebhookHandler) ProcessEvent ¶
func (wh *WebhookHandler) ProcessEvent(eventData map[string]interface{}) error
ProcessEvent processes a webhook event
func (*WebhookHandler) VerifySignature ¶
func (wh *WebhookHandler) VerifySignature(payload, signature string) bool
VerifySignature verifies a webhook signature
func (*WebhookHandler) VerifyTimestamp ¶
func (wh *WebhookHandler) VerifyTimestamp(timestamp string) error
VerifyTimestamp verifies a webhook timestamp
func (*WebhookHandler) VerifyWebhook ¶
func (wh *WebhookHandler) VerifyWebhook(payload, signature, timestamp string) error
VerifyWebhook verifies a webhook