Configuration Options
The LicenseManager in the SDK provides several configuration options that allow you to tailor its behavior to your specific use cases, including air-gapped environments, logging control, offline support, and more.
Custom Logger (Resty)
The License Manager uses a Resty client to communicate with LicenseSpring’s API. By default, Resty logs to standard output. You can override this behavior by passing a custom logger using WithRestyLogger.
WithRestyLogger(restyLogger resty.Logger)type CustomLogger struct{}
func (fl *CustomLogger) Debugf(format string, v ...interface{}) {}
func (fl *CustomLogger) Errorf(format string, v ...interface{}) {}
func (fl *CustomLogger) Warnf(format string, v ...interface{}) {}
lm_config := license_manager.LicenseManagerBasicConfiguration{
OAuth: false,
ApiKey: "your-api-key",
SharedKey: "your-shared-key",
ProductCode: "your-product-code",
AuthData: auth.FromKey("LICENSE-KEY"),
}
lm, _ := license_manager.NewLicenseManager(
lm_config,
license_manager.WithRestyLogger(CustomLogger),
)
cfg.Manager = lm
lh, _ := license_handler.NewLicenseHandler(cfg)WithAirGapPublicKey
WithGracePeriod
By default, the SDK allows the license to be offline for 48 hours before invalidating it. This option lets you customize the duration of this grace period.
WithSyncPeriod
Sets how frequently (in seconds) the SDK should try to synchronize the license with the server.
WithRestyVerbose
When set to true, the SDK outputs detailed logs for LicenseClient operations.
WithVerifySignature
When enabled, this option enforces signature verification on all responses from LicenseSpring.
WithEnableGuardFile
This enables the use of guard files to protect against reuse of offline activation requests and ensure that hardware IDs match.
WithHardwareId
Overrides the hardware ID used to identify the device.
WithAppName
Overrides the App Name.
WithAppVersion
Overrides the App Version.
WithServerPublicKey
Overrides the server public key used to verify the signature in API responses. Setting up this value is mandatory if you are using a server other than LicenseSpring's servers.
WithHardwareIdAlgo
Overrides the hardware ID used to identify the device. You can use this configuration option if you want to enable the built-in hardware ID module, which supports multiple hardware ID algorithms. You’ll need to select one of the supported algorithms from the list below:
HWIDAlgorithmWindowsFingerprint
HWIDAlgorithmComputerSystemProduct
HWIDAlgorithmCryptography
HWIDAlgorithmLinuxMachineID
HWIDAlgorithmCloudPlatform
Each algorithm generates the hardware ID differently depending on the operating system and environment. Choose the one that best fits your use case.
WithMachineId
Overrides the hardware ID and sets it to match the machine ID used in SDK v1. Use this option if you want to maintain compatibility with the hardware ID format from v1.
Hardware Key Support
Starting with Go SDK v2.1.0, the SDK supports hardware keys and licenses that require a provisioned hardware key to be attached to the machine for all API calls. To use these licenses, you must initialize the SDK with additional configuration options so it can detect the hardware key, derive the correct hardware ID, and perform signing.
WithHardwareKeySerial
Required when using a hardware key.
This option configures the SDK to use the hardware key with the specified serial number for authentication and uses that serial number as the hardware ID. The License API validates the hardware ID against the provisioned hardware key. If a key with the specified serial number is not present, an error is returned. When the key is present, licenses activated through this manager are bound to that hardware key and will continue to work only while the key is present and the manager is configured to use the same serial number.
If you do not know the serial number, call ListHWKeySerials() from either the license_manager or bundle_manager module to retrieve the serial numbers of the connected hardware keys and select the one you want to use.
WithHWKeySerialAsHWID
Deprecated as of v2.2.0. Use WithHardwareKeySerial(serial string) instead.
For Go SDK v2 up to v2.1.3, this option forces the SDK to use the hardware key’s serial number as the hardware ID. The License API validates the hardware ID against the provisioned hardware key; if this option is not enabled, the hardware ID will not match and API calls will fail. Starting with v2.2.0, use WithHardwareKeySerial(serial string) instead, which provides a simpler and more explicit way to configure the hardware key. WithHWKeySerialAsHWID() is retained for backward compatibility. When used, the SDK searches for a connected hardware key and returns an error if none or more than one are found. If exactly one key is found, its serial number is used as the hardware ID and as the configured hardware key serial.
WithCryptoSigner
Advanced / uncommon. Use this only if you are using a hardware key license but want to provide your own signer implementation. In most cases you do not need this option.
WithEnableHWKEYVerify
Skip hardware key verification entirely.
Only with this configuration, the SDK will check for the presence of the hardware key and will skip hardware-key verification logic. otherwise.
WithHardwareKeyPIN
Set a custom PIN for the hardware key.
If you have changed the hardware key PIN, provide it here. Otherwise, the SDK uses the default PIN: "123456".
Last updated
Was this helpful?