-
Notifications
You must be signed in to change notification settings - Fork 0
config_en.md
The config package provides a flexible, powerful, and structured configuration management solution specifically designed for HypGo. It supports reading YAML configuration files, environment variable expansion, parameter validation, and default value handling.
-
YAML Support and Deserialization: Through
mapstructureandyamltags, configuration files can be easily mapped to structs. -
Flexible Configuration Sources: The
LoadConfigmethod allows loading a configuration file from a given path into the application; an error is thrown if the path doesn't contain a configuration. -
Interface Isolation Design: Defines a series of interfaces (
ConfigInterface,ServerConfigInterface,DatabaseConfigInterface,RedisConfigInterface,LoggerConfigInterface) to provide clear constraints and improve testability for configuration objects. -
Read-Write Separation Configuration Support: Provides
ReplicaConfigProviderandDatabaseConfig.Replicasconfiguration for easily setting up multiple Read Replicas, with easy fallback to the primary database. -
Advanced Validation Support: Integrates validation tools from
@maoxiaoyue/hypgo/pkg/jsonor other validation strategies to verify that configuration values are required or conform to specified formats.
The following example demonstrates how to load a configuration file named config.yaml:
package main import ( "log" "github.com/maoxiaoyue/hypgo/pkg/config" ) func main() { // Assuming config.yaml exists cfg, err := config.LoadConfig("config.yaml") if err != nil { log.Fatalf("Unable to load configuration: %v", err) } // Ensure all values have default fallbacks cfg.ApplyDefaults() log.Printf("Server will start on %s", cfg.GetServerConfig().GetAddr()) }
The configuration is divided into three main sections:
- Server: Server connection settings, Protocol (HTTP2/3, etc.), TLS, and Graceful Restart configuration.
- Database: Connection driver, DSN, connection pool settings, as well as Redis and multiple Data Replicas configuration.
- Logger: Output log level, format, output destination, etc.
Example config.yaml:
server: addr: ":8080" protocol: "HTTP/1.1" database: driver: "mysql" dsn: "user:pass@tcp(127.0.0.1:3306)/dbname" logger: level: "info" format: "json"
If certain parameters are not provided, calling cfg.ApplyDefaults() defaults to:
- Server
addr::8080 - Server
protocol:HTTP/1.1 - Read/Write Timeout:
10/10 - Logger
level:info - DB MaxIdle/Open Conns etc. also have built-in default references
v0.8.5+LLMConfigandllm.yamlare new in v0.8.5 and are not available in v0.8.1.
HypGo provides a standalone LLM configuration file for controlling the Manifest smart enrichment feature. Place it at config/llm.yaml or .hyp/llm.yaml.
type LLMConfig struct { Mode string `yaml:"mode"` // "none", "rag", "ollama", "api" RAG RAGConfig `yaml:"rag"` // used when mode=rag Ollama OllamaConfig `yaml:"ollama"` // used when mode=ollama API APIConfig `yaml:"api"` // used when mode=api }
| Mode | Description | Cost |
|---|---|---|
none |
No LLM, pure Go inference only (default) | Zero |
ollama |
Connect to local Ollama server | Free (local compute) |
api |
Connect to remote API (OpenAI / Anthropic / Gemini) | Pay-per-use |
rag |
Vector DB + embedding + LLM generation | Pay-per-use |
mode: ollama ollama: url: "http://localhost:11434" # default model: "llama3" # required timeout: 30 # seconds (default 30) max_tokens: 256 # default 256
Supports 4 providers: openai, anthropic, gemini, custom.
mode: api api: provider: "openai" # required model: "gpt-4o-mini" # required api_key: "${OPENAI_API_KEY}" # required (supports ${ENV_VAR}) base_url: "" # each provider has a default timeout: 30 # seconds (default 30) max_tokens: 256 # default 256
Provider Default BaseURLs:
| Provider | Default BaseURL |
|---|---|
openai |
https://api.openai.com/v1 |
anthropic |
https://api.anthropic.com/v1 |
gemini |
https://generativelanguage.googleapis.com/v1beta |
custom |
Must be set manually |
mode: rag rag: embedding_model: "nomic-embed-text" # required embedding_url: "http://localhost:11434" # default Ollama vector_store: "chroma" # required: chroma/qdrant/milvus/faiss vector_store_url: "http://localhost:8000" # required collection: "my_codebase" # collection name top_k: 5 # retrieval count (default 5) generator_model: "llama3" # required generator_url: "http://localhost:11434" # default Ollama
// Load from path (returns mode=none defaults if file doesn't exist) cfg, err := config.LoadLLMConfig("config/llm.yaml") // Empty path → mode=none cfg, err := config.LoadLLMConfig("") // Check if enabled if cfg.IsEnabled() { // mode != "none" }
-
API Key Environment Variables:
api_keysupports${ENV_VAR}syntax to avoid storing keys in plaintext - Manifest Safety: LLM configuration never appears in Manifest output
- Response Sanitization: LLM responses are cleaned — HTML/script tags removed, length limited to 500 characters
-
Local-First: Ollama defaults to
localhostonly
See pkg/config/llm_example.yaml for a fully commented example.
設計文件
套件
- config — 設定
- context — 請求上下文
- router — 路由器
- server — 伺服器
- middleware — 中介層
- websocket — WebSocket
- hidb — 資料庫 ORM
- hidb/cassandra — Cassandra
- logger — 日誌
- json — JSON 處理
- grpc — gRPC
AI 協作工具鏈
- schema — Schema-first 路由
- manifest — 專案 Manifest
- contract — Contract Testing
- errors — Typed Error Catalog
- migrate — Migration Diff
- scaffold — 智慧 Scaffold
- airules — AI Rules
CLI 命令
- hyp 總覽
- hyp new
- hyp api
- hyp run
- hyp restart
- hyp generate
- hyp migrate
- hyp context
- hyp ai-rules
- hyp chkcomment
- hyp impact
- hyp docker
- hyp health
- hyp version
- hyp difflog
Design Docs
Packages
- config — Configuration
- context — Request Context
- router — Router
- server — Server
- middleware — Middleware
- websocket — WebSocket
- hidb — Database ORM
- hidb/cassandra - Cassandra 5.0
- logger — Logger
- json — JSON
- grpc — gRPC
AI Collaboration Toolchain
- schema — Schema-first Routing
- manifest — Project Manifest
- contract — Contract Testing
- errors — Typed Error Catalog
- migrate — Migration Diff
- scaffold — Smart Scaffold
- airules — AI Rules
CLI Commands