feat(api-gateway): 添加content服务代理路由

main.go添加textbooks/chapters/knowledge-points/questions四组路由

config.go新增ContentServiceURL字段

docs: known-issues记录P4 content端到端验证经验
This commit is contained in:
SpecialX
2026-07-09 08:52:30 +08:00
parent 921fe82771
commit 5f18821302
3 changed files with 29 additions and 6 deletions

View File

@@ -14,6 +14,7 @@ type Config struct {
IamServiceURL string
TeacherBffURL string
CoreEduServiceURL string
ContentServiceURL string
OTLPEndpoint string
LogLevel string
DevMode bool
@@ -29,6 +30,7 @@ func Load() *Config {
IamServiceURL: getEnv("IAM_SERVICE_URL", "http://localhost:3002"),
TeacherBffURL: getEnv("TEACHER_BFF_URL", "http://localhost:3003"),
CoreEduServiceURL: getEnv("CORE_EDU_SERVICE_URL", "http://localhost:3004"),
ContentServiceURL: getEnv("CONTENT_SERVICE_URL", "http://localhost:3005"),
OTLPEndpoint: getEnv("OTEL_EXPORTER_OTLP_ENDPOINT", "http://localhost:4318"),
LogLevel: getEnv("LOG_LEVEL", "info"),
DevMode: getEnvBool("DEV_MODE", false),

View File

@@ -93,6 +93,21 @@ func main() {
api.Any("/homework/*path", coreEduHandler)
api.Any("/grades", coreEduHandler)
api.Any("/grades/*path", coreEduHandler)
// content 服务路由(教材/章节/知识点/题库)
contentProxy, err := proxy.NewProxy(cfg.ContentServiceURL)
if err != nil {
log.Fatalf("failed to create content proxy: %v", err)
}
contentHandler := proxy.ProxyHandler(contentProxy)
api.Any("/textbooks", contentHandler)
api.Any("/textbooks/*path", contentHandler)
api.Any("/chapters", contentHandler)
api.Any("/chapters/*path", contentHandler)
api.Any("/knowledge-points", contentHandler)
api.Any("/knowledge-points/*path", contentHandler)
api.Any("/questions", contentHandler)
api.Any("/questions/*path", contentHandler)
}
srv := &http.Server{