Idiomatic Go client for the Deps API.
The deps-go package is a lightweight and powerful client for interacting with the Deps API in any Go environment.
- Idiomatic Go: Clean, facade-based Go code that feels natural to use.
- Typed: Fully typed with Go structs for a better developer experience.
- Lightweight: Minimal dependencies.
- Flexible: Configure the HTTP client, timeout, and base URL with functional options.
go get go.depscian.tech@v1.1.1The Client is the main entry point for interacting with the Deps API.
Example: Get the API status.
package main
import (
"context"
"fmt"
"log"
depsclient "go.depscian.tech"
)
func main() {
client, err := depsclient.NewClient("YOUR_API_KEY")
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
status, err := client.Status.Get(context.Background())
if err != nil {
log.Fatalf("Failed to get status: %v", err)
}
fmt.Printf("Arizona Servers: %d\n", len(status.Arizona))
}The NewClient function accepts your apiKey and a variable number of functional options.
| Name | Type | Description |
|---|---|---|
apiKey |
string |
Your Deps API key. This is a required parameter. |
WithBaseURL |
func(string) Option |
Overrides the base URL of the Deps API. Defaults to https://api.depscian.tech/v2. |
WithTimeout |
func(time.Duration) Option |
Sets a custom timeout for the HTTP client. Defaults to 30s. |
WithHTTPClient |
func(*http.Client) Option |
Allows you to use a completely custom http.Client. |
The client provides access to the API through a set of services:
client.Adminsclient.Familiesclient.Fractionsclient.Ghettoclient.Leadershipclient.Mapclient.Onlineclient.Playerclient.Sobesclient.Status
The client returns a standard Go error. For API calls that can result in a "not found" state (like finding a player), the client returns a specific depsclient.ErrNotFound error. You can use errors.Is to check for this case.
Example: Find a player and handle the ErrNotFound case.
package main
import (
"context"
"errors"
"fmt"
"log"
depsclient "go.depscian.tech"
)
func main() {
client, err := depsclient.NewClient("YOUR_API_KEY")
if err != nil {
log.Fatalf("Failed to create client: %v", err)
}
var serverId int = 1
var nickname string = "NonExistentPlayer"
player, err := client.Player.Find(context.Background(), serverId, nickname)
if err != nil {
if errors.Is(err, depsclient.ErrNotFound) {
fmt.Println("Player not found.")
} else {
// Handle other errors (network, server-side, etc.)
log.Fatalf("API Error: %v", err)
}
return
}
// The 'player' variable is a clean struct, not a response wrapper.
fmt.Printf("Player ID: %d\n", player.Id)
}