Building Steamer: A Resilient DNS TUI with Go

Managing DNS records often involves wrestling with slow web interfaces or hunting through documentation for the right API endpoint. With Steamer, I wanted to build a tool that felt fast, looked good in the terminal, and handled the quirks of a production API with grace.

The Tech Stack

Steamer is built with:

  • Go: For speed and its excellent concurrency model.
  • Bubble Tea: The foundation for the interactive Terminal UI (TUI).
  • Cobra: To handle CLI commands like list-domains and add-cname.
  • Viper: For resilient configuration management.

Lessons in API Resilience

One of the biggest challenges when building against a production API like Porkbun is dealing with inconsistent return types. Some fields might return a string in one scenario and an int in another.

1. Handling Type Inconsistency

To prevent unmarshaling errors, I adopted a pattern of using interface{} for potentially volatile fields:

type Record struct {
    ID interface{} `json:"id"` // Might be "123" or 123
    // ...
}

By using %v in fmt.Sprintf, I can safely handle these values regardless of their underlying type.

2. XDG-Compliant Configuration

Configuration should be flexible but standardized. Steamer supports the XDG Base Directory Specification, prioritizing ~/.config/steamer/config.yaml while maintaining backward compatibility for legacy paths.

3. TUI Alignment and Clean Escapes

When building tables in Bubble Tea, clean formatting is essential. A common pitfall is accidental escape characters in format strings (like %-10s) which can cause the fmt package to output raw type information instead of the formatted string. Keeping the format strings "naked" ensures the TUI stays sharp.

Why it Matters

Tools like Steamer aren't just about saving a few clicks; they're about reducing the friction between an idea and its deployment. By moving DNS management to the terminal, I can go from a new project idea to a configured CNAME in seconds.

You can find the source and installation instructions at github.com/ghchinoy/steamer.