> For the complete documentation index, see [llms.txt](https://docs.licensespring.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.licensespring.com/sdks/go-sdk/v1-legacy/go-license-client.md).

# Go License Client

{% hint style="info" %}
LicenseSpring’s new [**Go SDK V2**](broken://pages/ae2a7abe98ac54bb39ee8fc9e008316b6c214907) is now available! This version is a complete rewrite with breaking changes and will receive all future updates and support.

The legacy Go SDK (v1) is deprecated and maintained for backward compatibility only. New users should use v2.
{% endhint %}

{% hint style="info" %}
**Note:** Read [**Common**](broken://pages/ba35f6f80b4e589e98545732a1aa580f61301d98) before this.
{% endhint %}

#### Importing the License Client

```go
import (
	"gitlab.com/l3178/sdk-go/license_client"
	"gitlab.com/l3178/sdk-go/core/auth"
	core_request "gitlab.com/l3178/sdk-go/core/models/request"
)
```

#### Create LicenseClient

The following function uses the default `CryptoProvider` and `DataLocation` to encrypt, store, and decrypt the license file. You can implement your custom `CryptoProvider` and `DataLocation` the interface structure.

```go
config := license_client.NewLicenseClientConfiguration("apiKey", "sharedKey", "productCode")
client := license_client.NewLicenseClient(config)
```

#### Create Custom LicenseClient

Implement the `CryptoProvider` and `DataLocation` interfaces to create custom implementations for these components, and use them to configure the license client.

```go
// implement the interface:
//type CryptoProvider interface {
//	Encrypt(core_models.LicenseFile, string) (interface{}, error)
//	Decrypt(interface{}, string) (interface{}, error)
//}
type CustomCryptoProvider struct{}
func (d CustomCryptoProvider) Encrypt(license_file core_models.LicenseFile, password string) (interface{}, error) {
	// your custom implementation
}
func (d CustomCryptoProvider) Decrypt(data interface{}, password string) (interface{}, error) {
	// your custom implementation
}

// implement the interface:
//type DataLocation interface {
//	DataDirectory() (string, error)
//	LicenseFileName(string) string
//}
type CustomDataLocation struct{}
func (d CustomDataLocation) DataDirectory() (string, error) {
	// your custom implementation
}
func (d CustomDataLocation) LicenseFileName(productCode string) string {
	// your custom implementation
}

config := license_client.NewLicenseClientConfigurationCustom(CustomCryptoProvider, CustomDataLocation, "apiKey", "sharedKey", "productCode")
client := license_client.NewLicenseClient(config)
```

#### Activate Key-Based License

After activating the license, this function saves the license file in the location specified by the `DataLocation` object. The file is securely encrypted using the implementation provided by the `CryptoProvider`.

```go
resp := client.ActivateLicense(license_client.ActivationRequest{
	LicenseRequest: core_request.LicenseRequest{
		Auth: auth.FromKey("licenseKey"),
	},
	Hostname:   "hostname",
	AppVersion: "1.1.1",
	...
})
```

#### Activate User-Based License

After activating the license, this function saves the license file in the location specified by the `DataLocation` object. The file is securely encrypted using the implementation provided by the `CryptoProvider`.

```go
resp := client.ActivateLicense(license_client.ActivationRequest{
	LicenseRequest: core_request.LicenseRequest{
		Auth: auth.FromUsername("username", "password"),
	},
	Hostname:   "hostname",
	AppVersion: "1.1.1",
	...
})
```

#### Deactivate Key-Based License

```go
err := client.DeactivateLicense(license_client.LicenseRequest{
	Auth: auth.FromKey("licenseKey"),
})
```

#### Deactivate User-Based License

```go
err := client.DeactivateLicense(license_client.LicenseRequest{
	Auth: auth.FromUsername("username", "password"),
})
```

#### Check Key-Based License

```go
resp := client.CheckLicense(license_client.ActivationRequest{
	LicenseRequest: core_request.LicenseRequest{
		Auth: auth.FromKey("licenseKey"),
	},
	...
})
```

#### Check User-Based License

```go
resp := client.CheckLicense(license_client.ActivationRequest{
	LicenseRequest: core_request.LicenseRequest{
		Auth: auth.FromUsername("username", "password"),
	},
	...
})
```

#### Activate Offline License

After activating the license, this function saves the license file in the location specified by the `DataLocation` object. The file is securely encrypted using the implementation provided by the `CryptoProvider`.

```go
// Generate offline license request data
resp := client.GenerateOfflineLicenseRequest(license_client.ActivationRequest{
	LicenseRequest: core_request.LicenseRequest{
		Auth:       auth.FromKey("licenseKey"),
	},
}, license_client.OfflineActivationRequest)

// Write to request file if you want to activate license manually
encoded, err := resp.Value.Encode()
ioutil.WriteFile("activate_offline.req", []byte(encoded), os.ModePerm)

// Activate offline license using API
client.ActivateOffline(offlineLicenseRequest)
```

#### Deactivate Offline License

```go
// Generate offline license request data
resp := client.GenerateOfflineLicenseRequest(license_client.ActivationRequest{
	LicenseRequest: core_request.LicenseRequest{
		Auth:       auth.FromKey("licenseKey"),
	},
}, license_client.OfflineDeactivationRequest)

// Write to request file if you want to deactivate license manually
encoded, err := resp.Value.Encode()
ioutil.WriteFile("deactivate_offline.req", []byte(encoded), os.ModePerm)

// Deactivate offline license using API
client.DeactivateOffline(offlineLicenseRequest)
```

#### Local License Check

This function reads the license file from local memory, validates it by performing checks such as expiration and hardware ID matching, and returns the license object along with the results of these checks.

```go
clientConfig := license_client.NewLicenseClientConfiguration(
	config.ApiKey,
	config.SharedKey,
	productCode,
)
clientConfig.Verbose = config.Verbose
clientConfig.VerifySignature = config.VerifySignature

client := license_client.NewLicenseClient(clientConfig)

resp := client.ActivateLicense(context.Background(), license_client.ActivationRequest{
	LicenseRequest: core_request.LicenseRequest{
		Product: productCode,
		Auth:    auth.FromKey(productAuth.LicenseKey),
	},
})

resp2 := client.LocalLicenseCheck(context.Background(),
	license_client.LocalLicenseCheckRequest{Product: productCode})
```

Local license check returns an object of the following type:

{% code title="local\_check\_response.go" %}

```go
type LocalCheckResponse struct {
	LicenseResponse

	LicenseActive  bool `json:"license_active"`
	LicenseEnabled bool `json:"license_enabled"`
	IsExpired      bool `json:"is_expired"`

	DeviceLicensed bool `json:"is_device_licensed"`
	IsClockTampered  bool `json:"is_clock_tampered"`
	ProductMismatch bool `json:"product_mismatch"`
	FloatingExpired bool `json:"floating_expired"`
}
```

{% endcode %}

#### Add Consumption

```go
// Add 1 consumption
resp := client.AddConsumption(license_client.ConsumptionRequest{
	LicenseRequest: core_request.LicenseRequest{
		Auth: auth.FromKey("licenseKey"),
	},
	Consumptions: 1,
})

// Add 1 consumption, allow overages and define max overages
resp := client.AddConsumption(license_client.ConsumptionRequest{
	LicenseRequest: core_request.LicenseRequest{
		Auth: auth.FromKey("licenseKey"),
	},
	Consumptions:  1,
	MaxOverages:   5,
	AllowOverages: true,
})
```

#### Add Feature Consumption

```go
resp := client.AddFeatureConsumption(license_client.FeatureConsumptionRequest{
	LicenseRequest: license_client.LicenseRequest{
		Auth: core_request.Auth{}.FromKey("licenseKey"),
	},
	Feature:      "featureCode",
	Consumptions: 1,
})
```

#### Trial Key

```go
resp := client.TrialKey(license_client.TrialLicenseRequest{
	LicenseRequest: core_request.LicenseRequest{
		Auth: auth.FromKey("licenseKey"),
	},
	Email:         "",
	LicensePolicy: "",
	FirstName:     "",
	LastName:      "",
	Phone:         "",
	Address:       "",
	PostCode:      "",
	State:         "",
	Country:       "",
	City:          "",
	Reference:     "",
})
```

#### Product Details

```go
// takes product code from configuration
resp := client.ProductDetails()
```

#### Track Device Variables

```go
err := client.TrackDeviceVariables(license_client.DeviceVariablesRequest{
	LicenseRequest: core_request.LicenseRequest{
		Auth: auth.FromKey("licenseKey"),
	},
	Variables: map[string]string{
		"key": "var",
	},
})
```

#### Get Device Variables

```go
resp := client.GetDeviceVariables(license_client.LicenseRequest{
	Auth: auth.FromKey("licenseKey"),
})
```

#### Floating Borrow

```go
resp := client.FloatingBorrow(license_client.FloatingBorrowRequest{
	LicenseRequest: license_client.LicenseRequest{
		Auth: auth.FromKey("licenseKey"),
	},
	BorrowedUntil: time.Now().UTC().Add(time.Hour * 24 * 5),
})
```

#### Floating Release

```go
client.FloatingRelease(license_client.LicenseRequest{
	Auth: auth.FromKey("licenseKey"),
})
```

#### Change Password

```go
client.ChangePassword(license_client.ChangePasswordRequest{
	PasswordAuth: core_request.PasswordAuth{
		Username: "username",
		Password: "password",
	},
	NewPassword: "abcd",
})
```

#### Versions

```go
resp := client.Versions(license_client.LicenseRequest{
	Auth: auth.FromKey("licenseKey"),
})
```

#### Installation File

```go
resp := client.InstallationFile(license_client.LicenseRequest{
	Auth: auth.FromKey("licenseKey"),
})
```

#### Customer License Users

```go
resp := client.CustomerLicenseUsers(license_client.CustomerLicenseUsersRequest{
	Customer: "customer",
})
```

#### SSO URL

```go
resp := client.SSOUrl(license_client.SSOUrlRequest{
	CustomerAccountCode: "code",
})
```

#### Air-Gap Initialization

```go
airgapClient := license_client.NewAirgapClient(config, "publicKey")
activationCode, err := airgapClient.AirgapInitialization("licenseKey", "signingKey")
return activationCode, cfg.HardwareId
```

#### Air-Gap Activation

```go
airgapClient := license_client.NewAirgapClient(config, "publicKey")
license, err := airgapClient.AirgapActivation("licensePolicy", "confirmationCode", 1234)
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.licensespring.com/sdks/go-sdk/v1-legacy/go-license-client.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
