> 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/v2/samples/how-to-run-the-sample-files.md).

# How to Run the Sample Files

Clear and practical samples are provided to demonstrate how to run specific licensing scenarios. You can use these samples as a foundation to build more advanced or customized workflows.

Currently, the samples require a config.yaml file located in the same directory. You must populate it with your credentials — including either OAuth credentials (client ID and client secret) or API/Shared keys — along with product details such as the product code and corresponding license credentials (either a license key or username/password pair).

Please note that most samples are written assuming key-based licenses by default, but you can easily adapt them for username/password licenses by updating the configuration.

#### Step 1: Fill out config.yaml

Here’s an example structure:

```yaml
clientId: "your-client-id"
clientSecret: "your-client-secret"
cryptoProviderKey: "your-crypto-provider-key" # Required if using OAuth
apiKey: "your-api-key"
sharedKey: "your-shared-key"
verbose: true
verify_signature: true

products:
  productCode1:
    licenseKey: "your-license-key"
  productCode2:
    username: "your-username"
    password: "your-password"
```

* If you are using **OAuth**, make sure to fill in the cryptoProviderKey field.
* If you are using **API/SharedKey** authentication, you can leave the OAuth fields empty.

{% stepper %}
{% step %}

### Running the Online Activation Sample

To run a sample that **activates**, **checks**, and **deactivates** a license, use the provided ExampleOnlineActivation() sample function.

Call this function inside your main function and provide it with two parameters:

* useOAuth (bool): Set to true if you are using OAuth authentication, otherwise false.
* productCode (string): The product code of the license you want to activate.

Example:

```go
func main() {
    err := ExampleOnlineActivation(true, "your-product-code")
    if err != nil {
        fmt.Println(err)
    }
}
```

{% hint style="info" %}
Important Notes:

* Ensure you have created a license that supports **online activation**.
* If you are using OAuth, make sure the first parameter (useOAuth) is set to true.
* All required credentials must be correctly set up in your config.yaml file.
  {% endhint %}
  {% endstep %}

{% step %}

### Running the Online Activation with Consumption Sample

This sample demonstrates how to **activate a license**, **add consumption**, **sync the consumption**, **revert** the license back to its previous state, and then **deactivate** it.

Use the provided ExampleOnlineActivationAddConsumption() function to perform this flow.

Call the function inside your main function and pass two parameters:

* useOAuth (bool): Set to true if you are using OAuth authentication, otherwise false.
* productCode (string): The product code for the **online consumption license** you want to test.

Example:

```go
func main() {
    err := ExampleOnlineActivationAddConsumption(true, "your-consumption-product-code")
    if err != nil {
        fmt.Println(err)
    }
}
```

{% hint style="info" %}
Important Notes:

* Ensure the license you use is a **consumption-based online license**.
* All required credentials and product information must be correctly configured in your config.yaml.
* If you are using OAuth, remember to pass true for the first parameter.
  {% endhint %}
  {% endstep %}
  {% endstepper %}

<details>

<summary>Additional samples in the repository</summary>

Similar to the samples explained here, there are additional sample files available in the repository. These cover a wide range of scenarios such as **offline activation**, **air-gapped environments**, **floating licenses**, and more. Each sample is provided with **detailed comments** to guide you step-by-step through the process.

</details>


---

# 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/v2/samples/how-to-run-the-sample-files.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.
