Skip to content

Deps-Tech/deps-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deps-go

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.

Features

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

Installation

go get go.depscian.tech@v1.1.1

Client API

The 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))
}

Constructor options

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.

API Modules

The client provides access to the API through a set of services:

  • client.Admins
  • client.Families
  • client.Fractions
  • client.Ghetto
  • client.Leadership
  • client.Map
  • client.Online
  • client.Player
  • client.Sobes
  • client.Status

Error Handling

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

LICENSE

MIT

About

Idiomatic Go client for the Deps API

Resources

License

Stars

Watchers

Forks

Languages