- monorepo: pnpm workspace + go.work + pyproject.toml + commitlint/husky - infra: docker-compose (minimal + full profiles) + init-sql + prometheus - arch-scan: multi-language scanner skeleton (TS/Go/Python/Proto) - shared-proto: buf v2 + classes.proto (ClassService CRUD contract) - api-gateway: Go/Gin + JWT HS256 auth + reverse proxy + request ID - classes: NestJS golden template (error system + observability + middleware + CRUD + tests) - teacher-portal: Next.js + paper-feel UI design system - CI/CD: 4 workflows (go/ts/py/proto) - docs: migration guide + project_rules + coding-standards + git-workflow + ui-design-system + 004 + 9 module READMEs + known-issues + spec/plan migration + roadmap
43 lines
931 B
Go
43 lines
931 B
Go
package routing
|
|
|
|
import (
|
|
"github.com/edu-cloud/api-gateway/internal/config"
|
|
"github.com/edu-cloud/api-gateway/internal/middleware"
|
|
"github.com/edu-cloud/api-gateway/internal/proxy"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// Setup 配置路由
|
|
func Setup(cfg *config.Config) *gin.Engine {
|
|
gin.SetMode(gin.ReleaseMode)
|
|
r := gin.New()
|
|
|
|
// 中间件
|
|
r.Use(middleware.RequestIDMiddleware())
|
|
r.Use(gin.Recovery())
|
|
|
|
// 健康检查(无需鉴权)
|
|
r.GET("/healthz", healthz)
|
|
|
|
// API v1 组(需要鉴权)
|
|
api := r.Group("/api/v1")
|
|
api.Use(middleware.AuthMiddleware(cfg))
|
|
{
|
|
// classes 服务路由
|
|
classesProxy, err := proxy.NewProxy(cfg.ClassesServiceURL)
|
|
if err != nil {
|
|
panic("failed to create classes proxy: " + err.Error())
|
|
}
|
|
api.Any("/classes/*path", proxy.ProxyHandler(classesProxy))
|
|
}
|
|
|
|
return r
|
|
}
|
|
|
|
func healthz(c *gin.Context) {
|
|
c.JSON(200, gin.H{
|
|
"status": "ok",
|
|
"service": "api-gateway",
|
|
})
|
|
}
|