How haproxytech/client-native works
Project Type and Purpose
• This is a Go-library (“client-native”) exposing two main clients:
– Configuration Client: read/modify HAProxy config files.
– Runtime Client: send commands and parse output over HAProxy’s UNIX stats socket.
• It also provides pluggable subsystems for storage (maps, SSL certs, general files) and SPOE.
• It uses code generation (go-swagger, internal generators) to produce models and parsers.
High-Level Component Identification
A. Application (your code that imports client-native)
B. client_native.New(...) Builder (entrypoint)
C. Sub-clients & modules
1. Configuration Module
2. Runtime Module
3. Storage Module(s)
4. SPOE Module
D. Code Generation Tools (cmd/*, specification/*)
E. Autogenerated Models (models/*)
F. Config-Parser Library (config-parser/*)
G. Underlying HAProxy Interfaces
1. HAProxy Config File on disk
2. HAProxy UNIX Socket (stats socket)
3. HAProxy SPOE Socket/Protocol
Relationships & Data Flows
• Application → calls client_native.New(opts...)
• Builder selects and wires:
– Configuration.New(...) → uses configuration/ + config-parser to load/validate config file → reads/writes disk.
– runtime_api.New(...) → uses runtime/ to open UNIX socket → send commands, parse responses.
– storage.New(...) → filesystem abstraction for maps, certificates, general files.
– spoe.NewSpoe(...) → uses spoe/* to talk SPE/Agent.
• All sub-clients rely on shared Models (models/*), autogenerated from the Swagger spec in specification/*.
• Code generation tools (cmd/kubebuilder_marker_generator, cmd/struct_equal_generator, etc.) consume specification/*.yaml and produce code under models/, configuration/, config-parser/parsers, etc.
Architectural Patterns & Principles
• Modular design: clearly separated modules for config, runtime, storage, spoe.
• Builder/Options pattern: client is configured by passing Option functions.
• Code-generation pipeline: specification YAML → go-swagger + internal cmd/* tools → autogenerated code.
• Clean separation:
– “runtime” for live interactions
– “configuration” + “config-parser” for static file manipulation
– “storage” for caching artifacts
– “spoe” for event processing