{"modulePath":"github.com/GoCodeAlone/workflow","version":"v0.87.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package licensing\n\nPackage licensing provides license validation and feature gating for the workflow engine.\n\n## Constants\n\n```go\nconst DefaultCacheTTL = 1 * time.Hour\n```\nDefaultCacheTTL is the default time to cache a valid license result.\n\n```go\nconst DefaultGracePeriod = 72 * time.Hour\n```\nDefaultGracePeriod is how long offline operation is allowed after the last successful validation before the license is considered expired.\n\n```go\nconst DefaultRefreshInterval = 1 * time.Hour\n```\nDefaultRefreshInterval is how often the background goroutine re-validates.\n\n## Types\n\n```go\ntype CompositeValidator struct {\n\t// contains filtered or unexported fields\n}\n```\nCompositeValidator tries an offline validator first, falling back to an HTTP validator. This enables air-gapped or low-latency license checks while keeping the HTTP validator as a fallback for online validation.\n\n```go\nfunc NewCompositeValidator(offline *OfflineValidator, http *HTTPValidator) *CompositeValidator\n```\nNewCompositeValidator creates a CompositeValidator from an offline and an HTTP validator. Either may be nil (though at least one should be non-nil).\n\n```go\nfunc (c *CompositeValidator) CanLoadPlugin(tier string) bool\n```\nCanLoadPlugin returns true when the offline validator permits the tier, or when there is no offline validator and the HTTP validator permits it.\n\n```go\nfunc (c *CompositeValidator) CheckFeature(feature string) bool\n```\nCheckFeature implements licensing.Validator. It uses the offline validator when available, otherwise falls back to the HTTP validator.\n\n```go\nfunc (c *CompositeValidator) GetLicenseInfo() *LicenseInfo\n```\nGetLicenseInfo implements licensing.Validator. It returns the offline license info when available (non-nil), otherwise falls back to the HTTP validator.\n\n```go\nfunc (c *CompositeValidator) Validate(ctx context.Context, key string) (*ValidationResult, error)\n```\nValidate implements licensing.Validator. It tries the offline validator first; if the result is valid it is returned immediately. Otherwise it falls back to the HTTP validator.\n\n```go\nfunc (c *CompositeValidator) ValidatePlugin(pluginName string) error\n```\nValidatePlugin implements plugin.LicenseValidator. It delegates to the offline validator, which performs the authoritative check without network calls.\n\n```go\ntype HTTPValidator struct {\n\t// contains filtered or unexported fields\n}\n```\nHTTPValidator validates licenses against a remote server with local caching and a grace period for offline operation.\n\n```go\nfunc NewHTTPValidator(cfg ValidatorConfig, logger *slog.Logger) *HTTPValidator\n```\nNewHTTPValidator creates a new HTTPValidator with the given config.\n\n```go\nfunc (v *HTTPValidator) CanLoadPlugin(tier string) bool\n```\nCanLoadPlugin returns true if the current license permits loading a plugin of the given tier.\n\n  - TierCore and TierCommunity: always allowed\n  - TierPremium: only allowed when license tier is \"professional\" or \"enterprise\"\n\n```go\nfunc (v *HTTPValidator) CheckFeature(feature string) bool\n```\nCheckFeature returns true if the current license includes the given feature.\n\n```go\nfunc (v *HTTPValidator) GetLicenseInfo() *LicenseInfo\n```\nGetLicenseInfo returns the current cached license info, or nil if no valid license is cached.\n\n```go\nfunc (v *HTTPValidator) Start(ctx context.Context) error\n```\nStart performs an initial validation and starts a background refresh goroutine.\n\n```go\nfunc (v *HTTPValidator) Stop(_ context.Context)\n```\nStop signals the background refresh goroutine to exit.\n\n```go\nfunc (v *HTTPValidator) Validate(ctx context.Context, key string) (*ValidationResult, error)\n```\nValidate returns the current license validation result. If a valid cached result exists, it is returned immediately. If the cached result is expired, remote validation is attempted. If remote validation fails, the grace period is checked.\n\n```go\ntype LicenseInfo struct {\n\tKey          string    `json:\"key\"`\n\tTier         string    `json:\"tier\"` // starter, professional, enterprise\n\tOrganization string    `json:\"organization\"`\n\tExpiresAt    time.Time `json:\"expires_at\"`\n\tMaxWorkflows int       `json:\"max_workflows\"`\n\tMaxPlugins   int       `json:\"max_plugins\"`\n\tFeatures     []string  `json:\"features\"`\n}\n```\nLicenseInfo contains the details of a validated license.\n\n```go\ntype OfflineValidator struct {\n\t// contains filtered or unexported fields\n}\n```\nOfflineValidator validates a license token using a local Ed25519 public key, with no network calls required after construction.\n\n```go\nfunc NewOfflineValidator(publicKeyPEM []byte, tokenStr string) (*OfflineValidator, error)\n```\nNewOfflineValidator parses publicKeyPEM and tokenStr, verifies the token signature, and returns an OfflineValidator ready for use.\n\n```go\nfunc (v *OfflineValidator) CanLoadPlugin(tier string) bool\n```\nCanLoadPlugin returns true when the given plugin tier is permitted by the license. Core and community plugins are always allowed. Premium plugins require a professional or enterprise tier that is not expired.\n\n```go\nfunc (v *OfflineValidator) CheckFeature(feature string) bool\n```\nCheckFeature implements licensing.Validator.\n\n```go\nfunc (v *OfflineValidator) GetLicenseInfo() *LicenseInfo\n```\nGetLicenseInfo implements licensing.Validator. Returns nil if the token is expired.\n\n```go\nfunc (v *OfflineValidator) Validate(_ context.Context, key string) (*ValidationResult, error)\n```\nValidate implements licensing.Validator. It returns a valid result when key matches the stored token string, and an invalid result otherwise.\n\n```go\nfunc (v *OfflineValidator) ValidatePlugin(pluginName string) error\n```\nValidatePlugin implements plugin.LicenseValidator. It returns an error if the token is expired, the tier is not professional or enterprise, or the plugin name is not listed in the token's feature set.\n\n```go\ntype ValidationResult struct {\n\tValid       bool        `json:\"valid\"`\n\tLicense     LicenseInfo `json:\"license,omitempty\"`\n\tError       string      `json:\"error,omitempty\"`\n\tCachedUntil time.Time   `json:\"cached_until\"`\n}\n```\nValidationResult holds the outcome of a license validation attempt.\n\n```go\ntype Validator interface {\n\tValidate(ctx context.Context, key string) (*ValidationResult, error)\n\tCheckFeature(feature string) bool\n\tGetLicenseInfo() *LicenseInfo\n}\n```\nValidator is the interface for license validation and feature checking.\n\n```go\ntype ValidatorConfig struct {\n\tServerURL       string\n\tLicenseKey      string\n\tCacheTTL        time.Duration\n\tGracePeriod     time.Duration\n\tRefreshInterval time.Duration\n}\n```\nValidatorConfig holds the configuration for creating an HTTPValidator.\n\n","path":"github.com/GoCodeAlone/workflow/licensing","name":"licensing","synopsis":"Package licensing provides license validation and feature gating for the workflow engine.","isRedistributable":true}
