Go guide
This page walks through the whole Go SDK in the order you would use it. Each step starts with the shortest code that works, then shows the other ways to write it.
Download the Go SDK if you have not done so yet.
Requirements
On Linux and macOS, NewAuthlyX returns an error because there is no Windows user ID to read. Use New with your own SystemID and Storage, as shown in Options.
Add the SDK to your project
Unzip the download into a folder in your project, for example authlyx, and point your go.mod at it:
Then import it. The package name is authlyx:
Create the client
The second value is your app’s AppKey. Find it in the dashboard under your application’s credentials. The third is the version of the program you are building. AuthlyX compares it with the versions you allow in the dashboard, so raise it each time you ship a new build. See Allowed Versions.
Create one client for the whole program. A package-level variable is the simplest way to share it:
Creating the client does not connect. Nothing is sent until you call Init. authlyx.Client is another name for the same type.
To change settings, start from the defaults:
All the options are listed in Options.
The context
Every call takes a context.Context first. It decides how long the call may run and lets you cancel it. When you do not need either, pass context.Background(). To give up after five seconds:
A cancelled call returns context.Canceled or context.DeadlineExceeded.
Ways to call the SDK
Calls return a Result and an error, and wait for the reply. That is normal Go and fits most programs.
Callbacks exist for InitAsync, InitializeAsync, LicenseLoginAsync, LoginAsync, GetVariableAsync and GetScriptAsync. A callback runs on its own goroutine. It always receives a Result: when the call fails, Success is false and Code and Message say why. The error the ...Async method returns only covers a missing callback.
Start the SDK
Call Init once, before signing in. Initialize is the same method with a longer name.
For the usual problems Init returns a Result with Success false and no error, so err is only set for unusual failures such as a reply that failed verification:
Sign in
LicenseLogin takes a license key, Login takes a username and password, and DeviceLogin signs in the current Windows user with no form. Device login only works for devices you approved first; see Device login.
When AuthlyX refuses a sign-in, err is set. It is an *authlyx.Error you can read with errors.As:
problem.Message is text you can show to the user; err.Error() puts the code in front of it. problem.Code is a fixed code for your own checks, such as INVALID_CREDENTIALS, LICENSE_NOT_FOUND, LICENSE_EXPIRED, LICENSE_BANNED, DEVICE_NOT_ALLOWED or DEVICE_LIMIT_REACHED. problem.Kind says what sort of problem it was:
All codes are on the Errors page.
A helper that turns any error into a message for the user:
With a callback, the result carries the outcome:
A sign-in function you can reuse:
Create an account, change the password, add time
RegisterUser creates a user account and signs it in. The other two need a signed-in user. All three report a refusal through err, the same way as sign-in.
Read the account
After sign-in, UserData returns a copy of the account details as a map[string]any:
Numbers come back as float64, as with any JSON in Go. Before sign-in and after sign-out the map is empty. Because the map is a copy, call UserData again when you want the latest values.
Functions that return text, numbers and yes/no
Reading a missing key with a type assertion would panic, so use the two-value form, or these helpers:
daysLeft rounds up, so one hour left counts as 1 day.
Features and metadata
Features come from the plan and the account. Some are on/off, some carry a value such as "high" or 90. Metadata is extra information attached to accounts. See Features and metadata.
Read them from the account
These do not contact AuthlyX:
The values refresh on every heartbeat, so dashboard changes show up without signing in again. For metadata helpers, copy the feature ones with "metadata" in place of "featureValues".
Ask AuthlyX directly
GetMetadata(ctx) with no key returns all metadata, like GetAllMetadata. To turn Data into your own struct, use authlyx.DecodeData:
Save metadata
Only keys you allowed for SDK writes in the dashboard can be changed.
Cloud variables
See Cloud variables.
Scripts
The third value is a revision number, or 0 for the newest. GetScriptAsync(ctx, name, revision, callback) is the callback form. The SDK checks the script’s signature before returning it. It does not run the script. See Scripts.
Logs and webhooks
Log writes a line to your app’s logs in the dashboard. SendWebhook sends an event to a webhook you set up in the dashboard; the third value can be a map or any struct that encodes to JSON.
Staying signed in
After sign-in the SDK checks in with AuthlyX in the background (a heartbeat), by default about every 10 minutes, and refreshes features and metadata each time. If you ban, pause or expire the account, the next heartbeat ends the session.
To be told when the session ends, set the callbacks in the options:
OnConnection receives online, disconnected or untrusted. Both run on a background goroutine, one event at a time, so keep them short. To check right away, call app.CheckSession(ctx); app.OnResume(ctx) does the same and is meant for when your app wakes from sleep. To run the heartbeat yourself, set options.Heartbeat = "manual" and call CheckSession from your own time.Ticker. More in Sessions and heartbeats.
Offline access
Later, without internet, Init returns OFFLINE_MODE with Success true, and the user signs in with the same license key or username and password. The SDK checks them against the saved permit and the sign-in succeeds with the code OFFLINE_ACCESS. app.HasOfflineAccess(ctx) tells you whether this PC has a valid saved permit. Signing out deletes it. See Offline access.
Updates
When this version is not allowed, Init fails with UPDATE_REQUIRED or VERSION_MISMATCH and the SDK shows a message box with the new version, release notes and a button to open your download page. To show your own window, set options.NoUpdatePrompt = true and read the details:
See Automatic updates.
Sign out and shut down
Logout ends the session, clears the account details and deletes saved offline access on this PC. It returns an error. Close stops the heartbeat; defer app.Close() right after creating the client is the usual pattern. A closed client cannot be used again.
Goroutines
The client is safe to use from several goroutines; calls on one client run one at a time. A common pattern is to start the SDK in the background while your program loads:
In a GUI toolkit, hand the result back to the UI thread the way your toolkit asks, for example with Fyne’s fyne.Do.
Results and errors
authlyx.Result has Success, Code, Message, RequestID and Data (map[string]any). authlyx.DecodeData[T](result) turns Data into your own type.
*authlyx.Error has Code, Message, Kind, RequestID, Status and Data.
Options
Start from authlyx.DefaultOptions(appKey, version) and change what you need:
A complete program
Each method also has its own page with every language side by side under SDK methods.

