Golang

🐼 Panda-Auth Go! - Golang Library Documentation

⚙️ 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 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

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:

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):

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 (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.

Example Usage (GetKey):

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

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

Here's the code from the example:

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.

Last updated