Go SDK
Go integration using the standard net/http package. No external dependencies required.
Zero dependencies — standard library only
Uses net/http and encoding/json from the Go standard library.
Installation
Copy the authon.go file into your project. No go modules needed beyond the standard library.
Project structure
text
myapp/
├── main.go
├── authon.go ← SDK file
└── go.modInitialize module
bash
go mod init myappSDK Implementation
authon.go
Go
package main
import (
"bytes"
"crypto/md5"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"runtime"
"time"
)
type Authon struct {
AppID string
ApiKey string
ApiURL string
SessionToken string
User UserData
App AppData
LastError string
Initialized bool
}
type UserData struct {
Username string `json:"username"`
Level int `json:"level"`
ExpiresAt string `json:"expiresAt"`
SessionToken string `json:"sessionToken"`
}
type AppData struct {
Name string `json:"name"`
Version string `json:"version"`
UpdateURL string `json:"updateUrl"`
}
type apiResponse struct {
Success bool `json:"success"`
Message string `json:"message"`
Data json.RawMessage `json:"data"`
}
func NewAuthon(appId, apiKey string) *Authon {
return &Authon{
AppID: appId,
ApiKey: apiKey,
ApiURL: "https://api.authon.pro",
}
}
func (a *Authon) post(data map[string]interface{}) (*apiResponse, error) {
data["appId"] = a.AppID
data["apiKey"] = a.ApiKey
body, _ := json.Marshal(data)
client := &http.Client{Timeout: 10 * time.Second}
resp, err := client.Post(a.ApiURL+"/v1", "application/json", bytes.NewReader(body))
if err != nil {
a.LastError = err.Error()
return nil, err
}
defer resp.Body.Close()
var result apiResponse
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
a.LastError = err.Error()
return nil, err
}
if !result.Success {
a.LastError = result.Message
}
return &result, nil
}
func (a *Authon) Init() bool {
result, err := a.post(map[string]interface{}{"type": "init"})
if err != nil || !result.Success {
return false
}
json.Unmarshal(result.Data, &a.App)
a.Initialized = true
return true
}
func (a *Authon) Login(username, password, hwid string) bool {
data := map[string]interface{}{
"type": "login", "username": username, "password": password,
}
if hwid != "" {
data["hwid"] = hwid
}
result, err := a.post(data)
if err != nil || !result.Success {
return false
}
json.Unmarshal(result.Data, &a.User)
a.SessionToken = a.User.SessionToken
return true
}
func (a *Authon) Register(username, password, licenseKey, hwid string) bool {
data := map[string]interface{}{
"type": "register", "username": username,
"password": password, "licenseKey": licenseKey,
}
if hwid != "" {
data["hwid"] = hwid
}
result, err := a.post(data)
if err != nil || !result.Success {
return false
}
json.Unmarshal(result.Data, &a.User)
return true
}
func (a *Authon) License(licenseKey, hwid string) bool {
data := map[string]interface{}{"type": "license", "licenseKey": licenseKey}
if hwid != "" {
data["hwid"] = hwid
}
result, err := a.post(data)
if err != nil || !result.Success {
return false
}
json.Unmarshal(result.Data, &a.User)
a.SessionToken = a.User.SessionToken
return true
}
func (a *Authon) Check() bool {
result, err := a.post(map[string]interface{}{
"type": "check", "sessionToken": a.SessionToken,
})
return err == nil && result.Success
}
func (a *Authon) GetVar(key string) string {
result, err := a.post(map[string]interface{}{
"type": "var", "sessionToken": a.SessionToken, "key": key,
})
if err != nil || !result.Success {
return ""
}
var data struct{ Value string `json:"value"` }
json.Unmarshal(result.Data, &data)
return data.Value
}
func (a *Authon) SetVar(key, value string) bool {
result, err := a.post(map[string]interface{}{
"type": "setvar", "sessionToken": a.SessionToken,
"key": key, "value": value,
})
return err == nil && result.Success
}
func (a *Authon) DownloadFile(fileId string) ([]byte, error) {
result, err := a.post(map[string]interface{}{
"type": "file", "sessionToken": a.SessionToken, "fileId": fileId,
})
if err != nil || !result.Success {
return nil, fmt.Errorf(a.LastError)
}
var data struct{ DownloadURL string `json:"downloadUrl"` }
json.Unmarshal(result.Data, &data)
resp, err := http.Get(a.ApiURL + data.DownloadURL)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return io.ReadAll(resp.Body)
}
func (a *Authon) Log(message string) bool {
result, err := a.post(map[string]interface{}{
"type": "log", "sessionToken": a.SessionToken, "message": message,
})
return err == nil && result.Success
}
func GetHWID() string {
hostname, _ := os.Hostname()
data := fmt.Sprintf("%s-%s-%s", hostname, runtime.GOOS, runtime.GOARCH)
hash := md5.Sum([]byte(data))
return fmt.Sprintf("HWID-%X", hash[:6])
}
Quick Start
main.go
Go
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
const (
appID = "your-app-id"
apiKey = "your-api-key"
)
func main() {
auth := NewAuthon(appID, apiKey)
reader := bufio.NewReader(os.Stdin)
// Initialize
fmt.Println("[*] Connecting...")
if !auth.Init() {
fmt.Printf("[!] Failed: %s\n", auth.LastError)
os.Exit(1)
}
fmt.Printf("[+] Connected to %s v%s\n", auth.App.Name, auth.App.Version)
// Login
hwid := GetHWID()
fmt.Print("Username: ")
username, _ := reader.ReadString('\n')
username = strings.TrimSpace(username)
fmt.Print("Password: ")
password, _ := reader.ReadString('\n')
password = strings.TrimSpace(password)
if !auth.Login(username, password, hwid) {
fmt.Printf("[!] Login failed: %s\n", auth.LastError)
os.Exit(1)
}
fmt.Printf("[+] Welcome %s!\n", auth.User.Username)
fmt.Printf(" Level: %d\n", auth.User.Level)
fmt.Printf(" Expires: %s\n", auth.User.ExpiresAt)
// Verify session
if auth.Check() {
fmt.Println("[+] Session verified.")
}
// Log activity
auth.Log("User logged in from Go app")
// Get server variable
version := auth.GetVar("app_version")
if version != "" {
fmt.Printf(" Server version: %s\n", version)
}
fmt.Println("\nApplication ready!")
}
License-Only Authentication
License key validation
Go
auth := NewAuthon(appID, apiKey)
auth.Init()
key := "AUTH-XXXX-XXXX-XXXX" // from user input
hwid := GetHWID()
if auth.License(key, hwid) {
fmt.Printf("[+] License valid! Level: %d\n", auth.User.Level)
fmt.Printf(" Expires: %s\n", auth.User.ExpiresAt)
} else {
fmt.Printf("[!] Invalid: %s\n", auth.LastError)
}
Server Variables
Working with variables
Go
// Get app-level variable
downloadURL := auth.GetVar("download_url")
latestVersion := auth.GetVar("app_version")
// Set user-level variable
auth.SetVar("theme", "dark")
auth.SetVar("last_used", "2025-06-15")
fmt.Printf("Download URL: %s\n", downloadURL)
fmt.Printf("Latest version: %s\n", latestVersion)
File Download
Download a protected file
Go
// Download file after authentication
fileBytes, err := auth.DownloadFile("your-file-id")
if err != nil {
fmt.Printf("[!] Download failed: %s\n", err.Error())
return
}
err = os.WriteFile("downloaded_module.bin", fileBytes, 0644)
if err != nil {
fmt.Printf("[!] Write failed: %s\n", err.Error())
return
}
fmt.Printf("[+] File downloaded (%d bytes)\n", len(fileBytes))
Error Handling
Error handling pattern
Go
if !auth.Login(username, password, hwid) {
switch {
case strings.Contains(auth.LastError, "Invalid credentials"):
fmt.Println("Wrong username or password")
case strings.Contains(auth.LastError, "Hardware ID mismatch"):
fmt.Println("This account is locked to another device")
case strings.Contains(auth.LastError, "Account banned"):
fmt.Println("Your account has been suspended")
case strings.Contains(auth.LastError, "Subscription expired"):
fmt.Println("Your subscription has expired")
default:
fmt.Printf("Error: %s\n", auth.LastError)
}
}
Notes
Go Version
Requires Go 1.16+ for io.ReadAll. Works with any Go version that supports modules.
Cross-Platform
Compiles to a single static binary for any OS. Use GOOS=windows go build for Windows targets.
Concurrency
The SDK is not goroutine-safe. Use a mutex if sharing an Authon instance between goroutines.
Build Size
Use go build -ldflags="-s -w" and UPX to minimize output binary size.