Go SDK
An idiomatic Go client, with a context.Context on every call. It requires Go 1.23 or later.
go get github.com/licenseman/licensemanager-gopkg.go.dev · GitHub · API Reference
How it works
A client holds one service per section of the API Reference , like client.LicensesAPI or client.CustomersAPI, and each service has one method per endpoint, named after it: Create a license is CreateLicense. A method takes the context and the path parameters, and returns a request: set its body and optional parameters with its methods, then send it with Execute(), which returns the response, the raw *http.Response, and an error.
The API Reference shows the Go call for every endpoint: it’s the place to look for what a method takes and returns.
Authentication
Credentials go in the context of each call:
import (
"context"
"os"
licensemanager "github.com/licenseman/licensemanager-go"
)
client := licensemanager.NewAPIClient(licensemanager.NewConfiguration())
// With an API key, from your backend:
ctx := context.WithValue(context.Background(), licensemanager.ContextAPIKeys, map[string]licensemanager.APIKey{
"apiKey": {Key: os.Getenv("LICENSEMANAGER_API_KEY")},
})
// With a token scoped to a customer, license or machine:
ctx = context.WithValue(context.Background(), licensemanager.ContextAccessToken, token)Never ship an API key in your application: anyone could extract it from the binary. Keep it on your servers.
Examples
Create a license after a sale, and email its key to the customer:
body := licensemanager.NewCreateLicense("jane@example.com")
body.SetSendKey(true)
license, _, err := client.LicensesAPI.CreateLicense(ctx, "x7Kp2QaZ").
CreateLicense(*body).
Execute()Validate a key from your application, which needs no credentials:
token, _, err := client.LicensesAPI.ValidateKey(context.Background(), "x7Kp2QaZ").
ValidateKey(*licensemanager.NewValidateKey("7KQ2M-X9ZPA-H4TRC-WN6EY-B3JDF", "4c:32:75:8f:9a:1e", "1.4.2")).
Execute()
// token.License is the signed license token.List the licenses of a product, one page at a time:
list, _, err := client.LicensesAPI.ListLicenses(ctx, "x7Kp2QaZ").
Page(2).
PageSize(50).
Sort("-createdAt").
Execute()
// list.Data holds the licenses, list.Pagination the totals.Errors
A failed request returns a *licensemanager.GenericOpenAPIError, holding the response body with the error’s stable code:
_, _, err := client.LicensesAPI.GetLicense(ctx, "l3Nv8KwB").Execute()
var apiErr *licensemanager.GenericOpenAPIError
if errors.As(err, &apiErr) {
// The body is { "error": { "code", "message" } }.
log.Println(apiErr.Error(), string(apiErr.Body()))
}