How sohaha/hub-api works
Project type and purpose
• This is a Go-based, monolithic backend HTTP service (“hub-api”) whose purpose is to sit in front of multiple large-language-model providers (e.g. OpenAI), perform load balancing, failover, model mapping, and expose a unified API for chat completions, model listing, and provider configuration.
File structure
• Top level:
• main.go – entry point
• Dockerfile, GitHub Actions workflows, GoReleaser config – build & deploy
• go.mod/go.sum – dependency management
• internal/
• app.go – application bootstrap (load config, start scheduler)
• router.go – HTTP router (mounts v1 and admin routes)
• controller/ – HTTP handlers (index.go, v1.go)
• errcode/ – centralized error codes & i18n
• module.go – module registration
• tasks.go – background tasks (health checks, cooldown resets)
• module/chat/
• chat_controller.go – business logic for chat endpoints
• parse.go/conf.go/provider_controller.go – request parsing, config APIs
• provider/openai/
• llm.go – OpenAI provider implementation
• json.go – JSON marshalling/unmarshalling
• Configuration files (config.toml, provider.json) are read at startup or updated via API.
Key insights from README
• Features: multiple LB algorithms, failover/silence, model mapping
• Usage: HTTP API, Docker container, systemd service
• Config: two layers (program config + per-provider JSON)
• Endpoints:
• POST /v1/chat/completions
• GET /v1/models
• GET/POST under /chat for provider management