depsclient

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2025 License: MIT Imports: 6 Imported by: 0

README

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

Functions

This section is empty.

Types

type AdminsService

type AdminsService service

func (*AdminsService) Get

func (s *AdminsService) Get(ctx context.Context, serverID int) (*apiclient.AdminsResponse, error)

type Client

type Client struct {
	Admins     *AdminsService
	Families   *FamiliesService
	Fractions  *FractionsService
	Ghetto     *GhettoService
	Leadership *LeadershipService
	Map        *MapService
	Online     *OnlineService
	Player     *PlayerService
	Sobes      *SobesService
	Status     *StatusService
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiKey string, opts ...Option) (*Client, error)

type FamiliesService

type FamiliesService service

func (*FamiliesService) Get

func (s *FamiliesService) Get(ctx context.Context, serverID, famID int) (*apiclient.FamilyResponse, error)

func (*FamiliesService) List

type FractionsService

type FractionsService service

func (*FractionsService) GetMembers

func (s *FractionsService) GetMembers(ctx context.Context, serverID int, fractionID string) (*apiclient.FractionResponse, error)

func (*FractionsService) List

type GhettoService

type GhettoService service

func (*GhettoService) Get

func (s *GhettoService) Get(ctx context.Context, serverID int) (*apiclient.GhettoResponse, error)

type LeadershipService

type LeadershipService service

func (*LeadershipService) GetLeaders

func (s *LeadershipService) GetLeaders(ctx context.Context, serverID int) (*apiclient.LeadersResponse, error)

func (*LeadershipService) GetSubleaders

func (s *LeadershipService) GetSubleaders(ctx context.Context, serverID int) (*apiclient.SubleadersResponse, error)

type MapService

type MapService service

func (*MapService) Get

func (s *MapService) Get(ctx context.Context, serverID int) (*apiclient.MapResponse, error)

type OnlineService

type OnlineService service

func (*OnlineService) Get

type Option

type Option func(*http.Client, *string) error

func WithBaseURL

func WithBaseURL(url string) Option

func WithHTTPClient

func WithHTTPClient(customClient *http.Client) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

type PlayerService

type PlayerService service

func (*PlayerService) Find

func (s *PlayerService) Find(ctx context.Context, serverID int, nickname string) (*apiclient.PlayerResponse, error)

type SobesService

type SobesService service

func (*SobesService) Get

func (s *SobesService) Get(ctx context.Context, serverID int) (*apiclient.SobesResponse, error)

type StatusService

type StatusService service

func (*StatusService) Get

Directories

Path Synopsis
internal
client
Package client provides primitives to interact with the openapi HTTP API.
Package client provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL