1 Home
Virgil edited this page 2026-03-11 12:04:24 +00:00

go-infra

Module: forge.lthn.ai/core/go-infra

Infrastructure management for the Host UK production environment. Provides API clients for CloudNS DNS, Hetzner Cloud, and Hetzner Robot, plus a declarative infrastructure configuration model loaded from infra.yaml.

Architecture

File Purpose
config.go Config struct and Load()/Discover() for infra.yaml
client.go APIClient — shared HTTP client with auth, retries, JSON handling
cloudns.go CloudNSClient — DNS record management via CloudNS API
hetzner.go HCloudClient (Cloud API) + HRobotClient (Robot API)

CLI commands in cmd/prod/ (dns, lb, setup, ssh, status) and cmd/monitor/.

Key Types

Infrastructure Config

  • Config — Top-level config: Hosts, LoadBalancer, Network, DNS, SSL, Database, Cache, Containers, S3, CDN, CICD, Monitoring, Backups
  • Host — Server: FQDN, IP, PrivateIP, Type (hcloud/hrobot), Role (bastion/app/builder), SSH, Services
  • LoadBalancer — LB config with backends, health checks, listeners, SSL
  • DNS — Provider config with zones and records
  • Database — Cluster config (engine, version, nodes, backup)

API Clients

  • CloudNSClient — DNS operations: ListZones(), ListRecords(), CreateRecord(), UpdateRecord(), DeleteRecord(), EnsureRecord(), SetACMEChallenge(), ClearACMEChallenge()
  • HCloudClient — Hetzner Cloud: ListServers(), ListLoadBalancers(), GetLoadBalancer(), CreateLoadBalancer(), DeleteLoadBalancer(), CreateSnapshot()
  • HRobotClient — Hetzner Robot (dedicated): ListServers(), GetServer()
  • APIClient — Shared HTTP client with configurable auth and error handling

Usage

import "forge.lthn.ai/core/go-infra"

// Load infrastructure config
cfg, path, _ := infra.Discover(".")

// Get app servers
appServers := cfg.AppServers()

// DNS management
dns := infra.NewCloudNSClient(authID, password)
changed, _ := dns.EnsureRecord(ctx, "example.com", "www", "A", "1.2.3.4", 300)

// Hetzner Cloud
hcloud := infra.NewHCloudClient(token)
servers, _ := hcloud.ListServers(ctx)

Dependencies

  • gopkg.in/yaml.v3 — YAML config parsing
  • No core ecosystem dependencies (standalone)