Appearance
Keycrate Go SDK ​
Installation ​
bash
go get github.com/keycrate/keycrate-sdk/sdks/goQuick Start ​
go
package main
import (
"fmt"
"github.com/keycrate/keycrate-sdk/sdks/go"
)
func main() {
client := keycrate.New("https://api.keycrate.dev", "your-app-id")
result, err := client.Authenticate(keycrate.AuthenticateOptions{
License: "your-license-key",
})
if err != nil {
panic(err)
}
if result.Success {
fmt.Println("License verified!")
if key, ok := result.Data["key"].(string); ok {
fmt.Printf("License key: %s\n", key)
}
} else {
fmt.Printf("Error: %s\n", result.Message)
}
}Authentication ​
License Key ​
go
result, err := client.Authenticate(keycrate.AuthenticateOptions{
License: "your-license-key",
})Username & Password ​
go
result, err := client.Authenticate(keycrate.AuthenticateOptions{
Username: "user@example.com",
Password: "password123",
})With HWID (Hardware ID) ​
go
result, err := client.Authenticate(keycrate.AuthenticateOptions{
License: "your-license-key",
HWID: "device-id-12345",
})Registration ​
go
result, err := client.Register(keycrate.RegisterOptions{
License: "your-license-key",
Username: "newuser@example.com",
Password: "securepassword",
})
if err != nil {
panic(err)
}
if result.Success {
fmt.Println("Registration successful!")
} else {
fmt.Printf("Error: %s\n", result.Message)
}API Reference ​
New(host, appId) ​
Creates and returns a new client instance.
Parameters:
host(string): Base URL of the APIappId(string): Your application ID
Returns: *Client
client.Authenticate(opts AuthenticateOptions) ​
Authenticate using either a license key or username/password.
Parameters:
opts.License(string): License keyopts.Username(string): Usernameopts.Password(string): Passwordopts.HWID(string): Hardware ID
Returns: (*AuthResponse, error)
Note: Either License OR (Username + Password) must be provided.
client.Register(opts RegisterOptions) ​
Register credentials for a license.
Parameters:
opts.License(string): License key (required)opts.Username(string): Username (required)opts.Password(string): Password (required)
Returns: (*AuthResponse, error)
Response Structure ​
All endpoints return a response with the following structure:
go
type AuthResponse struct {
Success bool
Message string
Data map[string]interface{}
}The Data field contains additional information depending on the operation:
json
{
"key": "license-key-string",
"expires_at": "2025-12-31T23:59:59Z",
"hwid_reset_allowed": true,
"last_hwid_reset_at": "2025-01-15T10:30:00Z",
"hwid_reset_cooldown": 86400
}Error Handling ​
go
result, err := client.Authenticate(keycrate.AuthenticateOptions{
License: "key",
})
if err != nil {
log.Printf("Request failed: %v", err)
return
}
if !result.Success {
message := result.Message
data := result.Data
if strings.Contains(message, "expired") {
log.Println("Your license has expired")
if expires, ok := data["expires_at"].(string); ok {
log.Printf("Expired on: %s\n", expires)
}
} else if strings.Contains(message, "HWID") {
log.Println("Device mismatch")
if reset, ok := data["hwid_reset_allowed"].(bool); ok && reset {
log.Println("You can reset your HWID")
}
} else {
log.Printf("Authentication failed: %s", message)
}
return
}
log.Println("License verified!")