feat: implement gas and delivery admin systems
This commit is contained in:
@@ -11,6 +11,8 @@ import (
|
||||
"git.apinb.com/bsm-sdk/core/database"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/config"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/initdb"
|
||||
deliverylogic "git.apinb.com/heqiapp/platforms/backend/api/internal/logic/delivery"
|
||||
gaslogic "git.apinb.com/heqiapp/platforms/backend/api/internal/logic/gas"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/logic/platform"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
|
||||
"git.apinb.com/heqiapp/platforms/backend/api/internal/routers"
|
||||
@@ -34,6 +36,16 @@ func main() {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
case "gas-resource-contract":
|
||||
if err := writeGasResourceContract(os.Stdout); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
case "delivery-resource-contract":
|
||||
if err := writeDeliveryResourceContract(os.Stdout); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
case "mock-data":
|
||||
if err := writeMockData(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
@@ -54,7 +66,7 @@ func main() {
|
||||
}
|
||||
|
||||
func printUsage() {
|
||||
fmt.Fprintln(os.Stderr, "usage: platform-cli <version|resource-contract|migrate|mock-data>")
|
||||
fmt.Fprintln(os.Stderr, "usage: platform-cli <version|resource-contract|gas-resource-contract|delivery-resource-contract|migrate|mock-data>")
|
||||
}
|
||||
|
||||
type route struct {
|
||||
@@ -97,6 +109,49 @@ func writeResourceContract(output io.Writer) error {
|
||||
return json.NewEncoder(output).Encode(manifest{Resources: contracts, Routes: routes})
|
||||
}
|
||||
|
||||
func writeGasResourceContract(output io.Writer) error {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
engine := gin.New()
|
||||
routers.RegisterGas(serviceKey, 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, "/"+serviceKey+"/gas/v1"),
|
||||
})
|
||||
}
|
||||
expected := gaslogic.ExpectedResources()
|
||||
contracts := make([]contract, 0, len(expected))
|
||||
for _, item := range expected {
|
||||
contracts = append(contracts, contract{
|
||||
Domain: item.Domain, Name: item.Name, Path: item.Path,
|
||||
PageKind: item.PageKind, Mode: string(item.Mode),
|
||||
})
|
||||
}
|
||||
return json.NewEncoder(output).Encode(manifest{Resources: contracts, Routes: routes})
|
||||
}
|
||||
|
||||
func writeDeliveryResourceContract(output io.Writer) error {
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
engine := gin.New()
|
||||
routers.RegisterDelivery(serviceKey, 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, "/"+serviceKey+"/delivery/v1"),
|
||||
})
|
||||
}
|
||||
expected := deliverylogic.ExpectedResources()
|
||||
contracts := make([]contract, 0, len(expected))
|
||||
for _, item := range expected {
|
||||
contracts = append(contracts, contract{
|
||||
Domain: item.Domain, Name: item.Name, Path: item.Path, PageKind: item.PageKind, Mode: item.Mode,
|
||||
})
|
||||
}
|
||||
return json.NewEncoder(output).Encode(manifest{Resources: contracts, Routes: routes})
|
||||
}
|
||||
|
||||
func writeMockData() error {
|
||||
config.New("platform")
|
||||
if config.Spec.Databases == nil {
|
||||
|
||||
Reference in New Issue
Block a user