Urgent.News

What's breaking now, across thousands of outlets.

Tech

Stop Hand-Writing DefiLlama URLs: Meet defillama-go, a Go SDK for the Full API Surface

If you are building a Go service around DeFi data, the first prototype is usually straightforward: make an HTTP request, decode JSON, and move on. The friction arrives later. One endpoint lives on a different host. A token identifier needs path escaping. A rate limit needs a sensible response. A Pro key must not leak into application logs. An upstream API adds a field that your struct did not…

For developers building Go services on top of DeFi data, the initial prototype typically involves straightforward HTTP requests and JSON decoding. However, as usage expands, complexities arise such as varying endpoints, token identifier path escaping, rate limits, and unexpected API fields. These challenges can be mitigated with the defillama-go library, a small, idiomatic Go client for DefiLlama's Free and Pro APIs that provides a unified interface for accessing protocol TVL, token prices, stablecoins, yields, volumes, fees, bridges, real-world assets, equities, and more.

Defillama-go maps all 132 GET operations in the DefiLlama OpenAPI snapshot, including 31 Free operations and 101 Pro operations, into 21 services. The route registry, generated service methods, and API index are maintained through contract tests. While the SDK does not eliminate the need to comprehend data semantics, it significantly reduces the transport plumbing required in a production Go codebase.

Defillama-go handles URL construction, timeouts, parameter validation, error interpretation, retries, and authentication, streamlining the process without imposing a heavy framework on the application.

To use defillama-go, install the library into a Go 1.22+ module with "go get github.com/tigusigalpa/defillama-go". Create a client, specifying an optional timeout and a *http.Client for proxy, tracing, custom TLS, or shared timeout policies. The library exposes data domains as methods, accepting context.Context as the first argument.

The client constructor does not make a network request, allowing for early detection of invalid options and avoiding unexpected I/O during client construction. For Free endpoints, the library manages route metadata, simplifying the process of handling various endpoints served from different origins.

With defillama-go, developers can access services such as TVL(), Prices(), Stablecoins(), Yields(), Volumes(), Fees(), Bridges(), ETFs(), DAT(), Equities(), PreIPO(), RWA(), and others. Each API operation corresponds to a corresponding entry in the generated index, providing a navigable interface to the full range of DefiLlama's API capabilities.

This comprehensive yet manageable approach ensures developers can easily integrate DefiLlama's extensive data offerings into their Go applications while maintaining a clean and maintainable codebase.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Why Shift Left is Dead

AI-driven development is exposing risks before code is written, forcing security teams to move beyond shift-left and govern agents, prompts, tools and data across the entire development lifecycle.

More from Wednesday 23 September →