SDKs
...
Go SDK
v2
License Handler
14min
license handler the licensehandler is the primary entry point to the sdk it orchestrates the license activation and storage by combining two modules licensemanager handles license logic, requests, and validations storage persists license data (e g , license files, guard files) securely we provide a single setup function, setuphandler, which simplifies configuration and lets you use either api key authentication or oauth the newlicensehandler function is the primary way to set up and use the sdk it initializes and connects the core modules overview go func newlicensehandler( config licensehandlerconfig, ) ( licensehandler, error) config required configuration fields such as api keys, product code, and license key what it returns calling newlicensehandler constructs and returns a fully functional licensehandler with a configured licensemanager a configured storage backend a unified interface to handle license activation, checking, and storage operations basic setup minimal setup with defaults lm config = license manager licensemanagerbasicconfiguration{ 	 oauth false, 	 apikey "your api key", 	 sharedkey "your shared key", 	 productcode "your product code", 	 authdata auth fromkey("license key"), 	 } cfg = license handler licensehandlerconfig{ lm config, } lh, err = license handler newlicensehandler(cfg) if err != nil { log fatal(err) } this will use api key authentication default license manager default file based storage with encryption using the shared key advanced usage providing a custom licensemanager 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 withrestyverbose(true), license manager withhardwareid("abc"), ) cfg manager = lm lh, = license handler newlicensehandler(cfg) oauth setup when using oauth, you have two options manually create a licensemanager using oauth and inject it into the handler config lm config = license manager licensemanagerbasicconfiguration{ 	 oauth true, 	 clientid "your client id", 	 clientsecret "your client secret", 	 productcode "your product code", 	 authdata auth fromkey("license key"), 	 } 	 	 lm, = license manager newlicensemanager( lm config, ) cfg manager = lm lh, = license handler newlicensehandler(cfg) provide oauth related fields via configuration object , allowing newlicensehandler to construct the manager internally cfg = license handler licensehandlerconfig{ oauth true, productcode "your product code", authdata auth fromkey("license key"), clientid "placeholder", clientsecret "placeholder", cryptoproviderkey "placeholder", } lh, err = license handler newlicensehandler(cfg) if err != nil { log fatal(err) } license manager configuration options to initialize the sdk, you must provide basic credentials, such as the api key and shared key (or client id and client secret in oauth mode), along with the product code and license authentication credentials these are required when calling newlicensemanager() and must be passed using the licensemanagerbasicconfiguration struct additional configuration options, such as the hardware id algorithm, grace period, and other settings, come with sensible defaults however, you can override them using optional configuration functions, which are explained in the following sections type licensemanagerbasicconfiguration struct { 	oauth bool 	clientid string 	clientsecret string 	apikey string 	sharedkey string 	productcode string 	authdata auth auth } the licensemanager can be customized using a variety of configuration options these options allow you to control how the sdk behaves under different conditions such as air gapped environments, logging preferences, offline handling, and more available options withrestylogger(restylogger resty logger) withairgappublickey(airgappublickey string) withgraceperiod(graceperiod int) withsyncperiod(syncperiod int) withrestyverbose(verbose bool) withverifysignature(verifysig bool) withenableguardfile(enableguardfile bool) withhardwareid(hardwareid string) withbaseurl(url string) withhardwareidalgo(algo int) withmachineid() withserverpublickey(publickey string) withappname(appname string) withappversion(appversion string) each of these options can be passed to newlicensemanager( ) or newlicensemanageroauth( ) as variadic arguments to modify the default behavior special note on air gapped licenses when working with air gapped licenses, you must set the airgappublickey this can be done either during initialization or afterward lh, = license handler newlicensehandler(cfg) lh licensemanager licenseclient licenseclientconfiguration airgappublickey = "x" more detailes about the configuration options can be found in configuration options https //app archbee com/docs/fbt z5cu33d lvzx1frku/2 ge9mjayb2mrstfs5xpg providing custom storage with a custom crypto provider cp = crypto provider defaultcryptoprovider{} cp setkey(cfg sharedkey) fs = data handler defaultfilestorage{} fs setcryptoprovider(\&cp) cfg storage = fs lh, err = license handler newlicensehandler(cfg) lh licensemanager licenseclient airgappublickey = "your airgap public key" licensehandlerconfig fields type licensehandlerconfig struct { 	oauth bool 	clientid string 	clientsecret string 	cryptoproviderkey string 	apikey string 	sharedkey string 	productcode string 	authdata auth auth 	verbose logger verboselevel 	manager license manager licensemanager // optional 	storage data handler filestorage // optional } apikey, sharedkey, productcode, and authdata are required if you are using a api authention method if using oauth, set oauth to true, and in that case, clientid, clientid and cryptoproviderkey are required manager and storage are optional and allow injecting custom components