client

package
v0.0.0-...-4148e18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

View Source
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

func Base64Decode(data string) (string, error)

Base64Decode decodes a base64 string

func Base64Encode

func Base64Encode(data string) string

Base64Encode encodes a string to base64

func CapitalizeFirst

func CapitalizeFirst(text string) string

CapitalizeFirst capitalizes the first letter of a string

func CreateWebhookSignature

func CreateWebhookSignature(payload, secret string) string

CreateWebhookSignature creates a webhook signature

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes formats bytes into human readable format

func FormatDuration

func FormatDuration(seconds int64) string

FormatDuration formats duration in seconds

func FormatTimestamp

func FormatTimestamp(timestamp int64) string

FormatTimestamp formats a timestamp

func GenerateLicenseKey

func GenerateLicenseKey() string

GenerateLicenseKey generates a random license key

func GenerateUUID

func GenerateUUID() string

GenerateUUID generates a random UUID

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

func IsValidJSON(jsonString string) bool

IsValidJSON checks if a string is valid JSON

func IsValidURL

func IsValidURL(urlString string) bool

IsValidURL checks if a string is a valid URL

func JSONDeserialize

func JSONDeserialize(data string, obj interface{}) error

JSONDeserialize deserializes JSON to an object

func JSONSerialize

func JSONSerialize(obj interface{}) (string, error)

JSONSerialize serializes an object to JSON

func MD5

func MD5(data string) string

MD5 computes MD5 hash

func ParseTimestamp

func ParseTimestamp(timestamp string) (int64, error)

ParseTimestamp parses a timestamp string

func RetryWithBackoff

func RetryWithBackoff(fn func() error, maxRetries int, initialDelay time.Duration) error

RetryWithBackoff retries a function with exponential backoff

func SHA1

func SHA1(data string) string

SHA1 computes SHA1 hash

func SHA256

func SHA256(data string) string

SHA256 computes SHA256 hash

func SanitizeInput

func SanitizeInput(input string) string

SanitizeInput sanitizes user input

func SanitizeMetadata

func SanitizeMetadata(metadata map[string]interface{}) map[string]interface{}

SanitizeMetadata sanitizes metadata

func Sleep

func Sleep(duration time.Duration)

Sleep pauses execution for the specified duration

func Slugify

func Slugify(text string) string

Slugify converts a string to a URL-friendly slug

func ToPascalCase

func ToPascalCase(text string) string

ToPascalCase converts a string to PascalCase

func ToSnakeCase

func ToSnakeCase(text string) string

ToSnakeCase converts a string to snake_case

func TruncateString

func TruncateString(text string, maxLength int) string

TruncateString truncates a string to a maximum length

func URLDecode

func URLDecode(s string) (string, error)

URLDecode decodes a URL-encoded string

func URLEncode

func URLEncode(s string) string

URLEncode encodes a string for URL use

func ValidateAmount

func ValidateAmount(amount float64) bool

ValidateAmount validates an amount

func ValidateCurrency

func ValidateCurrency(currency string) bool

ValidateCurrency validates a currency code

func ValidateDateRange

func ValidateDateRange(startDate, endDate string) error

ValidateDateRange validates a date range

func ValidateEmail

func ValidateEmail(email string) bool

ValidateEmail validates an email address

func ValidateLicenseKey

func ValidateLicenseKey(licenseKey string) bool

ValidateLicenseKey validates a license key format

func ValidateNotEmpty

func ValidateNotEmpty(value, fieldName string) error

ValidateNotEmpty validates that a string is not empty

func ValidatePagination

func ValidatePagination(page, limit int) (int, int)

ValidatePagination validates pagination parameters

func ValidatePositive

func ValidatePositive(value float64, fieldName string) error

ValidatePositive validates that a number is positive

func ValidateRange

func ValidateRange(value, min, max float64, fieldName string) error

ValidateRange validates that a number is within a range

func ValidateUUID

func ValidateUUID(uuid string) bool

ValidateUUID validates a UUID format

func VerifyWebhookSignature

func VerifyWebhookSignature(payload, signature, secret string) bool

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

type PingResponse struct {
	Message string `json:"message"`
	Time    string `json:"time"`
}

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

type WebhookListResponse

type WebhookListResponse struct {
	Data  []Webhook `json:"data"`
	Total int       `json:"total"`
	Page  int       `json:"page"`
	Limit int       `json:"limit"`
}

WebhookListResponse represents a list of webhooks

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL