【架构优化】从 config.LoadEndpoints 中拆出端口解析 httpPortFromEnv 并合并重复的 trimURL(env()) 为 envURL

Aperta
#424 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@fx-kurumi ci sta già lavorando.

Dal 13/11/2026.

  • #425 di @fx-kurumi — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
go
Ambito
backend

Direzione di ricerca

Start in internal/config/endpoints.go, where LoadEndpoints repeats trimURL(env(...)) six times and inlines the AGENTFLOW_HTTP_PORT default and 1-65535 check. The refactor adds envURL and httpPortFromEnv and keeps the existing error text. Done means the internal/config tests, gofmt, and go vet pass. A linked pull request (#425) is already open, so check it before starting.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

现状问题

internal/config/endpoints.go 的 LoadEndpoints 里:

  • trimURL(env("AGENTFLOW_...")) 这个"读环境变量并当 URL 规整"的写法重复了 6 次(AGENTFLOW_WORKER_URL、AGENTFLOW_API_URL、AGENTFLOW_CONTROL_URL、两处 AGENTFLOW_PLATFORM_MCP_URL、AGENTFLOW_AGENT_TOOL_GATEWAY_URL),读起来噪音较多;
  • AGENTFLOW_HTTP_PORT 的默认值回退与 1~65535 校验内联在函数开头,与地址推导混在一起。

重构方案

  • 新增包内 helper envURL(key) = trimURL(env(key)),替换上述 6 处;
  • 拆出 httpPortFromEnv() (string, error),负责默认值回退与端口校验,错误文案保持 invalid AGENTFLOW_HTTP_PORT %q 不变;
  • LoadEndpoints 只保留按角色推导地址的逻辑。WithPrivateAgentToolGateway 中 env(...) == "" 的判断语义不同(值为 / 时),保持不动。

影响范围

仅 internal/config/endpoints.go 及其测试;导出接口、返回值与错误文案不变,无行为变化。

验证方式

  • 新增测试覆盖 httpPortFromEnv(默认值、合法值、非数字、越界)与 envURL(空白、尾部 /);
  • 原有 internal/config 测试全部通过;gofmt、go vet ./internal/config/、go test ./internal/config/。
Lingua principale
Go
Stelle
141
Fork
28
Merge medio
1g 15h
PR unite (30g)
113

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Tencent/LoopForge

Tutte le issue di Tencent/LoopForge

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.