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

Abierto
#424 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@fx-kurumi ya está trabajando en esto.

Desde el 13/11/2026.

  • #425 de @fx-kurumi — abierto

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
25/100
Tipo de issue
Refactorización
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
go
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

现状问题

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/。
Lenguaje dominante
Go
Estrellas
141
Forks
28
Merge medio
1 d 15 h
PR fusionados (30 d)
113

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Tencent/LoopForge

Todos los issues de Tencent/LoopForge

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.