# Using LexFloatClient with Go

## Adding licensing to your app

After you've added a product for your app in the admin portal, you will need to do the following things:

* Note the product id for the product (from the actions menu in the table).
* Download the example project from [Github](https://github.com/cryptlex/lexfloatclient-go/tree/main/examples)

The product id is the identifier of your product that is to be used in the code. The product id of the LexFloatServer and LexFloatClient must match.

### Adding the library to your app

LexFloatClient wrapper for Go can be easily installed using the **go get** command:

```bash
go get -u github.com/cryptlex/lexfloatclient-go
```

**Note:** In case you are using Windows, execute the following command after installation:

```
xcopy %USERPROFILE%\go\src\github.com\cryptlex\lexfloatclient-go\libs\windows_amd64\LexFloatClient.dll
```

This would copy the LexFloatClient.dll to your project directory.

{% hint style="info" %}
**LexFloatClient** requires the Microsoft Visual C++ 2015 (or later) Runtime on older Windows versions such as Windows 7, 8, or Server 2008/2012. If not already installed, install it from the official [Visual C++ Redistributable](https://www.microsoft.com/en-in/download/details.aspx?id=48145) or include the required DLLs with your installer.
{% endhint %}

{% hint style="info" %}
This package relies on `cgo` to interface with a C library. As a result, `cgo` must be enabled when building and using this package. Disabling `cgo` (e.g., by setting `CGO_ENABLED=0`) will result in compilation errors.
{% endhint %}

### Setting product id

The first LexFloatClient API function you need to use in your code is `SetHostProductId()`. It sets the product id of the product you will be adding licensing to.&#x20;

```python
lexfloatclient.SetHostProductId("PASTE_PRODUCT_ID");
```

### Requesting floating license

To receive a floating license, you will use `SetHostUrl()`, `SetFloatingLicenseCallback()` and `RequestFloatingLicense()`LexFloatClient API methods. It sets the LexFloatServer address, the callback for status notifications, contacts the server and receives the floating license.

```python
func main() {
	var status int
	status = lexfloatclient.SetHostProductId("PASTE_PRODUCT_ID")
	if lexfloatclient.LF_OK != status {
		fmt.Println("Error Code:", status)
		os.Exit(1)
	}
	status = lexfloatclient.SetHostUrl("http://localhost:8090")
	if lexfloatclient.LF_OK != status {
		fmt.Println("Error Code:", status)
		os.Exit(1)
	}
	lexfloatclient.SetFloatingLicenseCallback(licenseCallback)
	status = lexfloatclient.RequestFloatingLicense()
	if lexfloatclient.LF_OK != status {
		fmt.Println("Error Code:", status)
		os.Exit(1)
	}  
	fmt.Println("Success! License acquired.") 
}
```

The above code can be executed every time user starts the app or needs a new license.

### Renewing floating license

License lease automatically renews itself in a background thread. When a license is renewed or fails to renew, the callback is invoked (from the background thread).

```python
func licenseCallback(status int) {
	if status == lexfloatclient.LF_OK {
		fmt.Println("The license lease has renewed successfully.")
	} else if status == lexfloatclient.LF_E_LICENSE_NOT_FOUND {
		fmt.Println("he license expired before it could be renewed.")
	} else if status == lexfloatclient.LF_E_LICENSE_EXPIRED_INET {
		fmt.Println("The license expired due to network connection failure.")
	} else {
		fmt.Println("The license renew failed due to other reason. Error code:", status)
	}
}
```

### Dropping floating license

When your user is done using the app, the app should send a request to free the license, thereby making it available to other users. If the app doesn't, the license becomes useless (zombie) until lease time is over.

```python
lexfloatclient.DropFloatingLicense()
fmt.Println("Success! License dropped.")
```

The above code should be executed every time user closes the app.

## Need more help

In case you need more help with adding LexFloatClient to your app, we'll be glad to help you make the integration. You can either post your questions on our [support forum](https://forums.cryptlex.com) or can contact us through [email](mailto:support@cryptlex.com?Subject=Using%20LexFloatClient).


---

# Agent Instructions: 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.cryptlex.com/floating-licenses/on-premise-floating-licenses/using-lexfloatclient/using-lexfloatclient-with-go.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.
