Skip to navigation

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

SupportedRecommended
Go1.18 and newerThe current release
PackagesNone outside the standard library
WindowsAny Windows your Go version supports

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:

require github.com/authlyx/sdk-go/v3 v3.0.0
replace github.com/authlyx/sdk-go/v3 => ./authlyx

Then import it. The package name is authlyx:

import authlyx "github.com/authlyx/sdk-go/v3"

Create the client

ctx := context.Background()
app, err := authlyx.NewAuthlyX(ctx, "YOUR_APP_KEY", "1.0.0")
if err != nil {
log.Fatal(err)
}
defer app.Close()

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:

var app *authlyx.AuthlyX
func setup(ctx context.Context) error {
var err error
app, err = authlyx.NewAuthlyX(ctx, "YOUR_APP_KEY", "1.0.0")
return err
}

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:

func create(ctx context.Context) (*authlyx.AuthlyX, error) {
options, err := authlyx.DefaultOptions("YOUR_APP_KEY", "1.0.0")
if err != nil {
return nil, err
}
options.NoUpdatePrompt = true
options.RequestBudget = 15 * time.Second
return authlyx.New(ctx, options)
}

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:

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
started, err := app.Init(ctx)

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.

StyleLooks likeWaits?
Plain callstarted, err := app.Init(ctx)Yes
Goroutinego func() { app.Init(ctx) }()No
Callbackapp.InitAsync(ctx, func(r authlyx.Result) { ... })No

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.

started, err := app.Init(ctx)
if err != nil {
log.Fatal(err)
}
if !started.Success {
fmt.Println(started.Message)
return
}
app.InitAsync(ctx, func(started authlyx.Result) {
fmt.Println(started.Code, started.Message)
})

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:

CodeSuccessWhat happened
APP_INITIALIZEDtrueConnected. Continue to sign-in.
OFFLINE_MODEtrueNo internet, but this PC has saved offline access. See Offline access.
NETWORK_...falseNo internet and nothing saved. Ask the user to try again.
UPDATE_REQUIREDfalseThis version is older than the one in your dashboard. The SDK has already shown an update box.
VERSION_MISMATCHfalseThis version is newer than the dashboard version and is not allowed.
APP_DISABLEDfalseYou paused the app in the dashboard.

Sign in

_, err = app.LicenseLogin(ctx, "YOUR_LICENSE_KEY")
_, err = app.Login(ctx, "YOUR_USERNAME", "YOUR_PASSWORD")
_, err = app.DeviceLogin(ctx)

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:

if _, err := app.LicenseLogin(ctx, licenseKey); err != nil {
var problem *authlyx.Error
if errors.As(err, &problem) {
fmt.Println(problem.Message)
} else {
fmt.Println(err)
}
return
}
fmt.Println("Welcome")

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:

KindMeaningWhat to do
serverAuthlyX answered and said noShow the message
networkNo answer: no internet, firewall, timeoutAsk the user to retry. Do not treat it as a ban.
securityA reply failed verificationDo not unlock anything
storageThe SDK could not read or save its protected filesUsually a permissions problem
cancelledThe client was closedNothing

All codes are on the Errors page.

A helper that turns any error into a message for the user:

func message(err error) string {
var problem *authlyx.Error
if errors.As(err, &problem) {
return problem.Message
}
return err.Error()
}

With a callback, the result carries the outcome:

app.LicenseLoginAsync(ctx, licenseKey, func(result authlyx.Result) {
if result.Success {
fmt.Println("Welcome")
} else {
fmt.Println(result.Message)
}
})
app.LoginAsync(ctx, username, password, func(result authlyx.Result) {
fmt.Println(result.Code)
})

A sign-in function you can reuse:

func signIn(ctx context.Context, licenseKey string) (bool, string) {
if _, err := app.LicenseLogin(ctx, licenseKey); err != nil {
return false, message(err)
}
return true, ""
}

Create an account, change the password, add time

_, err = app.RegisterUser(ctx, "YOUR_USERNAME", "YOUR_PASSWORD", "YOUR_LICENSE_KEY")
_, err = app.ChangePassword(ctx, "CURRENT_PASSWORD", "NEW_PASSWORD")
_, err = app.RedeemLicense(ctx, "ANOTHER_LICENSE_KEY")

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:

user, err := app.UserData(ctx)
if err != nil {
return
}
fmt.Println(user["Username"], user["Plan"], user["ExpiryDate"])
KeyExampleGo type
Usernamemayastring, only set for username and password accounts
LicenseKeyMAYA-4R8P-2N6K-9Q3Wstring
Emailmaya@example.comstring
PlanPlusstring
ExpiryDate2027-04-30T23:59:59.000Zstring, or nil for lifetime access
SIDS-1-5-21-...string
DeviceLimit3float64
Country, IpAddressNGstring
typelicensestring: user, license or device
registeredAt, lastLogin2026-08-12T14:22:10.000Zstring
features["aim", "esp"][]any of strings
featureValues, metadata{"fov": 90}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:

func text(values map[string]any, key string) string {
if value, ok := values[key]; ok && value != nil {
return fmt.Sprint(value)
}
return ""
}
func expiryText(user map[string]any) string {
expiry := text(user, "ExpiryDate")
if len(expiry) < 10 {
return "Lifetime"
}
return strings.ReplaceAll(expiry[:10], "-", "/")
}
func daysLeft(user map[string]any) int {
ends, err := time.Parse(time.RFC3339, text(user, "ExpiryDate"))
if err != nil {
return 0
}
left := time.Until(ends)
if left <= 0 {
return 0
}
return int((left + 24*time.Hour - 1) / (24 * time.Hour))
}
func buildTopLine(ctx context.Context) string {
user, _ := app.UserData(ctx)
license := text(user, "LicenseKey")
if license == "" {
return " License: Null"
}
return " License: " + license + " | Expiry: " + expiryText(user)
}
func remainingDays(ctx context.Context) string {
user, _ := app.UserData(ctx)
if text(user, "Plan") == "" {
return "N/A"
}
if text(user, "ExpiryDate") == "" {
return "Lifetime"
}
return strconv.Itoa(daysLeft(user)) + "D"
}
func isPremium(ctx context.Context) bool {
user, _ := app.UserData(ctx)
return text(user, "Plan") == "Premium"
}

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:

func hasFeature(user map[string]any, name string) bool {
list, _ := user["features"].([]any)
for _, item := range list {
if item == name {
return true
}
}
return false
}
func feature(user map[string]any, name, fallback string) string {
values, _ := user["featureValues"].(map[string]any)
if value := text(values, name); value != "" {
return value
}
return fallback
}
func featureInt(user map[string]any, name string, fallback int) int {
number, err := strconv.ParseFloat(feature(user, name, ""), 64)
if err != nil {
return fallback
}
return int(number)
}
func featureBool(user map[string]any, name string, fallback bool) bool {
switch strings.ToLower(feature(user, name, "")) {
case "true", "1", "yes", "on":
return true
case "false", "0", "no", "off":
return false
}
return fallback
}
user, _ := app.UserData(ctx)
aim := hasFeature(user, "aim")
fov := featureInt(user, "fov", 90)
rainbow := featureBool(user, "rainbow", false)
metadata, _ := user["metadata"].(map[string]any)
discord := text(metadata, "discord")

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

all, _ := app.GetFeatures(ctx)
fmt.Println(all.Data["features"])
quality, _ := app.GetFeature(ctx, "quality")
fmt.Println(quality.Data["value"])
aimCheck, _ := app.CheckFeature(ctx, "aim")
enabled, _ := aimCheck.Data["enabled"].(bool)
everything, _ := app.GetAllMetadata(ctx)
discordValue, _ := app.GetMetadata(ctx, "discord")
vip, _ := app.CheckMetadata(ctx, "vip")
fmt.Println(enabled, everything.Data["metadata"], discordValue.Data["value"], vip.Data["enabled"])

GetMetadata(ctx) with no key returns all metadata, like GetAllMetadata. To turn Data into your own struct, use authlyx.DecodeData:

type featureValue struct {
Name string `json:"name"`
Value any `json:"value"`
}
result, err := app.GetFeature(ctx, "quality")
if err == nil {
decoded, _ := authlyx.DecodeData[featureValue](result)
fmt.Println(decoded.Value)
}

Save metadata

app.SetMetadata(ctx, "discord", "maya#1234")
app.SetMetadata(ctx, "level", 5)
app.SetMetadata(ctx, "vip", true)

Only keys you allowed for SDK writes in the dashboard can be changed.

Cloud variables

motd, err := app.GetVariable(ctx, "motd")
if err == nil {
fmt.Println(motd.Data["value"])
}
app.GetVariableAsync(ctx, "motd", func(result authlyx.Result) {
fmt.Println(result.Data["value"])
})
app.UpdateVariable(ctx, "last_build", "1.4.2")

See Cloud variables.

Scripts

script, err := app.GetScript(ctx, "startup", 0)
if err == nil {
content, _ := script.Data["content"].(string)
fmt.Println(content)
}

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

app.Log(ctx, "Opened the settings page")
app.SendWebhook(ctx, "purchase.clicked", map[string]any{"item": "skin_42", "price": 4.99})

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.

if !app.HasAccess(ctx) {
fmt.Println("Please sign in")
}

To be told when the session ends, set the callbacks in the options:

func createWithEvents(ctx context.Context) (*authlyx.AuthlyX, error) {
options, err := authlyx.DefaultOptions("YOUR_APP_KEY", "1.0.0")
if err != nil {
return nil, err
}
options.OnInvalidated = func(problem *authlyx.Error) {
fmt.Println("Signed out:", problem.Message)
os.Exit(0)
}
options.OnConnection = func(state string) {
fmt.Println("Connection:", state)
}
return authlyx.New(ctx, 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

if _, err := app.LicenseLogin(ctx, licenseKey); err == nil {
app.SaveOfflineAccess(ctx)
}

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:

started, _ := app.Init(ctx)
if started.Code == "UPDATE_REQUIRED" || started.Code == "VERSION_MISMATCH" {
update, _ := started.Data["update"].(map[string]any)
fmt.Println(started.Message, update["version"], update["url"], update["notes"])
}

See Automatic updates.

Sign out and shut down

app.Logout(ctx)
app.Close()

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:

done := make(chan authlyx.Result, 1)
go func() {
started, _ := app.Init(ctx)
done <- started
}()
loadAssets()
started := <-done
fmt.Println(started.Code)

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:

FieldDefaultWhat it does
NoUpdatePromptfalsetrue hides the built-in update boxes
RequestBudget8 secondsHow long one call may take, including retries
Heartbeat"server""manual" to run session checks yourself
OnInvalidatedNoneCalled when AuthlyX ends the session
OnConnectionNoneCalled when the connection state changes
BuildHash""This build’s hash, if you use Application hashes
StorageProtected files in %LOCALAPPDATA%\AuthlyX\v3Any type with Load, Save and Delete
SystemIDThe Windows user SIDRequired on Linux and macOS

A complete program

package main
import (
"bufio"
"context"
"errors"
"fmt"
"os"
"strings"
authlyx "github.com/authlyx/sdk-go/v3"
)
func main() {
ctx := context.Background()
app, err := authlyx.NewAuthlyX(ctx, "YOUR_APP_KEY", "1.0.0")
if err != nil {
fmt.Println(err)
return
}
defer app.Close()
started, err := app.Init(ctx)
if err != nil || !started.Success {
fmt.Println(started.Message, err)
return
}
input := bufio.NewReader(os.Stdin)
fmt.Print("License key: ")
licenseKey, _ := input.ReadString('\n')
if _, err := app.LicenseLogin(ctx, strings.TrimSpace(licenseKey)); err != nil {
var problem *authlyx.Error
if errors.As(err, &problem) {
fmt.Println(problem.Message)
} else {
fmt.Println(err)
}
return
}
user, _ := app.UserData(ctx)
fmt.Println("Plan:", user["Plan"])
if expiry, ok := user["ExpiryDate"].(string); ok {
fmt.Println("Expires:", expiry)
} else {
fmt.Println("Expires: Lifetime")
}
fmt.Print("Press Enter to sign out")
input.ReadString('\n')
app.Logout(ctx)
}

Each method also has its own page with every language side by side under SDK methods.