> For the complete documentation index, see [llms.txt](https://pelican-development.gitbook.io/pelinda-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pelican-development.gitbook.io/pelinda-documentation/client-apis/library-overview/other-libraries/golang.md).

# Golang

### ⚙️ Installation & Setup

#### 1. Get the Library

First, you need to obtain the Panda-Auth Go library files.

* Download the library from the official Panda Development source (e.g., [pandadevelopment.net](https://pandadevelopment.net/) or the specified GitHub repository).

#### 2. Project Integration

Once downloaded, place the `PandaAuth.go` file (or the entire library package if structured as such) directly into your Go project's folder.

**Example Folder Structure:**

```
your-go-project/
├── main.go             // Your main application file
├── PandaAuth.go        // The Panda-Auth library file
└── go.mod              // (if using Go modules)
```

![PandaAuth.go in project folder](https://raw.githubusercontent.com/Panda-Repositories/PandaKS_Libraries/refs/heads/main/Documentation/On%20Folder.png)

After placing the file, your project should be able to access the functions provided by the Panda-Auth library. If the library is a package, you'll import it as usual in your `.go` files.

#### 3. Dependencies

The Panda-Auth library and example usage may rely on the following external Go packages:

**User-Side (for example, clipboard interaction):**

* `github.com/atotto/clipboard`

**Library Internal Dependencies:**

* `crypto/sha256`
* `encoding/json`
* `fmt`
* `io`
* `net/http`

If you don't have these dependencies installed in your Go environment, you can get them using the Go CLI:

```bash
go get github.com/atotto/clipboard
# Standard library packages like crypto/sha256, encoding/json, etc., are built-in
# and do not require 'go get'.
```

Alternatively, if your project uses Go modules (`go.mod` file), these dependencies might be managed automatically when you build or run your project.

### 📚 Available Functions

The Panda-Auth Go library provides the following core functions for key validation and retrieval.

#### `ValidateKey(key string, service string) bool`

Checks with the Panda Development API if the provided standard license key is valid for the specified service. The validation process is secured, potentially involving checks against IP address and using SHA256 hashing for data integrity.

* **Parameters:**
  * `key` (string): The license key string to validate.
  * `service` (string): Your unique service identifier.
* **Returns:**
  * `bool`: `true` if the key is valid, `false` otherwise.

#### `ValidatePremiumKey(key string, service string) bool`

Similar to `ValidateKey`, but specifically checks if the provided key is a **premium** license key and is valid for the specified service. This allows for differentiating access levels or features based on key type.

* **Parameters:**
  * `key` (string): The premium license key string to validate.
  * `service` (string): Your unique service identifier.
* **Returns:**
  * `bool`: `true` if the key is a valid premium key, `false` otherwise.

**Example Usage (`ValidateKey` / `ValidatePremiumKey`):**

```go
package main

import (
	"fmt"
	// Assuming PandaAuth functions are in the same package or imported
)

func main() {
	key := "riot_hawvawh72151275yqfw" // Define the key to be checked
	service := "riotdevkit"           // Your service identifier

	// To validate any valid key (standard or premium):
	if ValidateKey(key, service) {
		fmt.Println("Success: Key is valid!")
		// Execute your script or grant access
	} else {
		fmt.Println("Not a valid key.")
	}

	// To specifically validate only premium keys:
	if ValidatePremiumKey(key, service) {
		fmt.Println("Success: Premium key is valid!")
		// Grant premium access
	} else {
		fmt.Println("Not a valid premium key (or not valid at all).")
	}
}
```

If the validation is successful, your application can proceed. A successful console output might look like:

![Successful validation output](https://raw.githubusercontent.com/Panda-Repositories/PandaKS_Libraries/refs/heads/main/Documentation/Sucess%20on%20bash%20window.png)*(Sample output from the Go example)*

#### `GetKey(service string) string`

Generates and returns a URL that users can visit to obtain a license key for the specified service. The key retrieval process might be linked to the user's IP address and secured using SHA256.

* **Parameters:**
  * `service` (string): Your unique service identifier for which the key is to be generated.
* **Returns:**
  * `string`: A URL string for key retrieval.

{% hint style="warning" %}
**External Link Disclaimer:**\
The URL generated by `GetKey` directs to an external Panda-Auth service. Users access this link at their own risk. For more information on SHA256, you can [learn more here](https://www.simplilearn.com/tutorials/cyber-security-tutorial/sha-256-algorithm).
{% endhint %}

**Example Usage (`GetKey`):**

This example demonstrates getting the key URL and copying it to the user's clipboard.

```go
package main

import (
	"fmt"
	"github.com/atotto/clipboard" // For clipboard functionality
	// Assuming PandaAuth functions are in the same package or imported
)

func main() {
	service := "riotdevkit" // Your service identifier

	keyURL := GetKey(service)
	err := clipboard.WriteAll(keyURL) // Copy the URL to the clipboard
	if err != nil {
		fmt.Println("Error copying to clipboard:", err)
		fmt.Println("Please copy this URL manually:", keyURL)
	} else {
		fmt.Println("Key retrieval URL copied to clipboard!")
	}
	fmt.Println("Paste the URL in your browser to proceed and get your key.")
}
```

### 🚀 Complete Example

A full, pre-made example for testing the library, including source code, is available in the official Panda libraries repository. You can find the `Test` release here: [PandaKS\_Libraries Golang Releases](https://github.com/Panda-Repositories/PandaKS_Libraries/releases/tag/Golang)

Here's the code from the example:

```go
package main

import (
	"fmt"
	"github.com/atotto/clipboard" // For clipboard functionality
	// Assuming PandaAuth.go is in the same directory, making its functions directly accessible
	// If PandaAuth is a separate package, you would import it, e.g., "yourproject/pandaauth"
)

func main() {
	service := "riotdevkit" // Your service identifier
	var key string          // Variable to store the user's input key

	fmt.Println("Insert your key:")
	fmt.Scanln(&key) // Read the key input from the user

	if ValidatePremiumKey(key, service) {
		fmt.Println("Success: Premium version access granted!")
	} else if ValidateKey(key, service) {
		fmt.Println("Success: Standard version access granted!")
	} else {
		fmt.Println("Invalid Key. A link to get a new key will be copied to your clipboard.")
		keyURL := GetKey(service)
		err := clipboard.WriteAll(keyURL)
		if err != nil {
			fmt.Println("Error copying to clipboard:", err)
			fmt.Println("Please manually visit:", keyURL)
		} else {
			fmt.Println("New key URL copied to clipboard. Paste it in your browser.")
		}
	}

	fmt.Println("\nPress ENTER to exit.")
	fmt.Scanln() // Wait for user to press Enter before exiting
}
```

This example prompts the user for a key, attempts to validate it first as a premium key, then as a standard key, and if both fail, provides a link to get a new key.

***

Remember to replace placeholder values like `"riotdevkit"` and example keys with your actual service identifiers and user-provided keys.


---

# 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://pelican-development.gitbook.io/pelinda-documentation/client-apis/library-overview/other-libraries/golang.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.
