2026-07-27 10:25:04 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2026-07-28 10:42:26 +08:00
|
|
|
"io"
|
2026-07-27 10:25:04 +08:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform"
|
|
|
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/routers"
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type route struct {
|
|
|
|
|
Method string `json:"method"`
|
|
|
|
|
Path string `json:"path"`
|
|
|
|
|
}
|
2026-07-28 10:42:26 +08:00
|
|
|
|
2026-07-27 10:25:04 +08:00
|
|
|
type contract struct {
|
|
|
|
|
Domain string `json:"domain"`
|
|
|
|
|
Name string `json:"name"`
|
2026-07-27 11:00:21 +08:00
|
|
|
Path string `json:"path"`
|
2026-07-27 10:25:04 +08:00
|
|
|
PageKind string `json:"pageKind"`
|
|
|
|
|
Mode string `json:"mode"`
|
|
|
|
|
}
|
2026-07-28 10:42:26 +08:00
|
|
|
|
2026-07-27 10:25:04 +08:00
|
|
|
type manifest struct {
|
|
|
|
|
Resources []contract `json:"resources"`
|
|
|
|
|
Routes []route `json:"routes"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-28 10:42:26 +08:00
|
|
|
func writeResourceContract(output io.Writer) error {
|
2026-07-27 10:25:04 +08:00
|
|
|
gin.SetMode(gin.ReleaseMode)
|
|
|
|
|
engine := gin.New()
|
|
|
|
|
routers.RegisterPlatform("heqi", engine)
|
|
|
|
|
routes := make([]route, 0, len(engine.Routes()))
|
|
|
|
|
for _, item := range engine.Routes() {
|
|
|
|
|
routes = append(routes, route{Method: item.Method, Path: strings.TrimPrefix(item.Path, "/heqi/platform/v1")})
|
|
|
|
|
}
|
|
|
|
|
expected := platform.ExpectedResources()
|
|
|
|
|
contracts := make([]contract, 0, len(expected))
|
|
|
|
|
for _, item := range expected {
|
2026-07-28 10:42:26 +08:00
|
|
|
contracts = append(contracts, contract{
|
|
|
|
|
Domain: item.Domain, Name: item.Name, Path: item.Path,
|
|
|
|
|
PageKind: item.PageKind, Mode: string(item.Mode),
|
|
|
|
|
})
|
2026-07-27 10:25:04 +08:00
|
|
|
}
|
2026-07-28 10:42:26 +08:00
|
|
|
return json.NewEncoder(output).Encode(manifest{Resources: contracts, Routes: routes})
|
2026-07-27 10:25:04 +08:00
|
|
|
}
|