Note: You must already have an API key. This SDK does not create organizations or API keys. Obtain your API key from your Erebrus dashboard or admin before using this SDK.
A Go SDK for interacting with the Erebrus DVPN (Decentralized VPN) service. This SDK provides a complete interface for authenticating, creating clients, and establishing VPN connections using WireGuard.
- Authentication: Secure API authentication with your API key
- Node Discovery: Get all available VPN nodes
- Client Creation: Create WireGuard clients for specific nodes
- VPN Connection: Establish and manage WireGuard VPN connections
- Configuration Management: Generate and manage WireGuard configuration files
go get github.com/NetSepio/erebrus-go-sdk
- Go 1.21 or higher
- WireGuard installed on your system
- Sudo privileges (for VPN connection management)
- An API key (get this from your Erebrus dashboard or admin)
Ubuntu/Debian:
sudo apt update
sudo apt install wireguard
CentOS/RHEL/Fedora:
sudo yum install wireguard-tools
# or for newer versions
sudo dnf install wireguard-tools
macOS:
brew install wireguard-tools
package main
import (
"fmt"
"log"
"github.com/NetSepio/erebrus-go-sdk/erebrus"
)
func main() {
apiKey := "YOUR_API_KEY_HERE" // <-- Set your API key here
// 1. Authenticate with the API key
token, err := erebrus.Authenticate(apiKey)
if err != nil {
log.Fatalf("Failed to authenticate: %v", err)
}
fmt.Printf("Authentication successful! Token: %s\n", token)
// 2. Get available nodes
nodes, err := erebrus.GetAllNodes(token)
if err != nil {
log.Fatalf("Failed to get nodes: %v", err)
}
fmt.Printf("Found %d active nodes\n", len(nodes))
if len(nodes) > 0 {
// TODO: Replace with the node ID of the node you want to connect to
nodeID := "YOUR_SELECTED_NODE_ID"
// 3. Create a client for the first node
client, err := erebrus.CreateClient(token, nodeID, "my-client")
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
// 4. Create WireGuard configuration
configPath, err := erebrus.CreateWireGuardConfig(client)
if err != nil {
log.Fatalf("Failed to create config: %v", err)
}
fmt.Printf("WireGuard configuration created at: %s\n", configPath)
// 5. Connect to VPN (optional, requires sudo)
success, err := erebrus.ConnectDvpn(token, nodeID)
if err != nil {
log.Fatalf("Failed to connect: %v", err)
}
fmt.Printf("Connected successfully: %v\n", success)
6. Disconnect when done (optional)
err = erebrus.DisconnectVPN("")
if err != nil {
log.Printf("Warning: Failed to disconnect: %v", err)
}
}
}
Authenticates with the API using your API key and returns an authentication token.
Parameters:
apiKey
: Your API key
Returns:
string
: Authentication tokenerror
: Error if authentication fails
Example:
token, err := erebrus.Authenticate(apiKey)
if err != nil {
log.Fatal(err)
}
Gets all available nodes in the network.
Parameters:
token
: Authentication token
Returns:
[]Node
: Array of available nodeserror
: Error if request fails
Example:
nodes, err := erebrus.GetAllNodes(token)
if err != nil {
log.Fatal(err)
}
for _, node := range nodes {
fmt.Printf("Node: %s (%s)\n", node.Name, node.Status)
}
Creates a client for a specific node.
Parameters:
token
: Authentication tokennodeID
: ID of the target nodeclientName
: Name for the client (optional, defaults to "client")
Returns:
*ClientResponse
: Client configuration dataerror
: Error if creation fails
Example:
client, err := erebrus.CreateClient(token, nodeID, "my-vpn-client")
if err != nil {
log.Fatal(err)
}
Creates a WireGuard configuration file from client data.
Parameters:
clientData
: Client response data from CreateClient
Returns:
string
: Path to the created configuration fileerror
: Error if creation fails
Example:
configPath, err := erebrus.CreateWireGuardConfig(client)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Config created at: %s\n", configPath)
Establishes a VPN connection to the specified node.
Parameters:
token
: Authentication tokennodeID
: ID of the target node
Returns:
bool
: True if connection successfulerror
: Error if connection fails
Example:
success, err := erebrus.ConnectDvpn(token, nodeID)
if err != nil {
log.Fatal(err)
}
if success {
fmt.Println("VPN connected successfully!")
}
Disconnects from the VPN connection.
Parameters:
configPath
: Path to WireGuard config file (optional, defaults to "erebrus-dvpn.conf")
Returns:
error
: Error if disconnection fails
Example:
err := erebrus.DisconnectVPN("")
if err != nil {
log.Printf("Warning: %v", err)
}
type Node struct {
ID string `json:"id"`
Status string `json:"status"`
Name string `json:"name"`
}
type ClientResponse struct {
Status int `json:"status"`
Message string `json:"message"`
Payload struct {
Client Client `json:"client"`
Endpoint string `json:"endpoint"`
ServerPublicKey string `json:"serverPublicKey"`
} `json:"payload"`
PrivateKey string `json:"privateKey,omitempty"`
PresharedKey string `json:"presharedKey,omitempty"`
}
The SDK uses Go's standard error handling pattern. All functions return an error as the last return value, which should be checked after each function call:
token, err := erebrus.Authenticate(apiKey)
if err != nil {
log.Fatalf("Failed to authenticate: %v", err)
}
- API keys and tokens should be stored securely
- WireGuard configuration files are created with restricted permissions (600)
- The SDK requires sudo privileges for VPN operations
- All network communications use HTTPS
- WireGuard not installed: Install WireGuard tools for your platform
- Permission denied: Ensure you have sudo privileges for VPN operations
- Network connectivity: Check your internet connection and firewall settings
- API errors: Verify your API key and token are valid
The SDK provides detailed logging for all operations. Check the console output for error messages and status updates.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
For support and questions, please open an issue on the GitHub repository.