feat(documents): rebuild project document workbench
This commit is contained in:
@@ -14,6 +14,10 @@ type RouteRegistrar interface {
|
||||
Register(router gin.IRouter)
|
||||
}
|
||||
|
||||
type PublicRouteRegistrar interface {
|
||||
RegisterPublic(router gin.IRouter)
|
||||
}
|
||||
|
||||
// NewRouter 创建仅暴露 /api/v1 业务契约的公开路由。
|
||||
func NewRouter(cfg config.Config, registrars ...RouteRegistrar) *gin.Engine {
|
||||
return newRouter(cfg, nil, registrars...)
|
||||
@@ -40,6 +44,11 @@ func newRouter(cfg config.Config, tokenVerifier func(string) (uint, error), regi
|
||||
api.GET("/status", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"timestamp": time.Now().UTC().Format(time.RFC3339Nano)})
|
||||
})
|
||||
for _, registrar := range registrars {
|
||||
if publicRegistrar, ok := registrar.(PublicRouteRegistrar); ok {
|
||||
publicRegistrar.RegisterPublic(api)
|
||||
}
|
||||
}
|
||||
if tokenVerifier != nil {
|
||||
api.Use(auth.RequireUser(tokenVerifier))
|
||||
}
|
||||
@@ -77,6 +86,7 @@ func cors(cfg config.Config) gin.HandlerFunc {
|
||||
c.Header("Vary", "Origin")
|
||||
c.Header("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
|
||||
c.Header("Access-Control-Allow-Headers", "Authorization, Content-Type")
|
||||
c.Header("Access-Control-Expose-Headers", "Content-Disposition")
|
||||
c.Header("Access-Control-Max-Age", "86400")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user