|
|
@@ -1,66 +1,26 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
- "git.sxidc.com/go-framework/baize"
|
|
|
- "git.sxidc.com/go-framework/baize/convenient/gateway"
|
|
|
- "git.sxidc.com/go-framework/baize/framework/binding"
|
|
|
- "git.sxidc.com/go-framework/baize/framework/core/api"
|
|
|
- "git.sxidc.com/go-framework/baize/framework/core/application"
|
|
|
+ "baize-demo/project/gateway/api"
|
|
|
DEATH "github.com/vrecan/death"
|
|
|
- "net/http"
|
|
|
"syscall"
|
|
|
)
|
|
|
|
|
|
-func main() {
|
|
|
- app := baize.NewApplication(application.Config{
|
|
|
- ApiConfig: application.ApiConfig{
|
|
|
- UrlPrefix: "/gateway/api",
|
|
|
- Port: "11000",
|
|
|
- },
|
|
|
- })
|
|
|
-
|
|
|
- app.Api().
|
|
|
- PrefixRouter().
|
|
|
- RegisterVersionedRouter("v1")
|
|
|
-
|
|
|
- gw := gateway.NewGateway()
|
|
|
- defer gateway.DestroyGateway(gw)
|
|
|
-
|
|
|
- v1Binder := binding.NewBinder(app.ChooseRouter(api.RouterPrefix, "v1"), app.Infrastructure())
|
|
|
-
|
|
|
- gw.BodyMapping(v1Binder, &gateway.BodyMapping{
|
|
|
- HttpMethod: http.MethodPost,
|
|
|
- RelativePath: "/class/create",
|
|
|
- ToUrl: "http://localhost:31000/example/api/v1/class/create",
|
|
|
- BodyMappingFunc: func(body []byte) ([]byte, error) {
|
|
|
- origin := make(map[string]any)
|
|
|
+// Version
|
|
|
+// curl -X GET "http://localhost:32000/gateway/api/version"
|
|
|
|
|
|
- err := json.Unmarshal(body, &origin)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- origin["studentNum"] = origin["studentNum1"]
|
|
|
- delete(origin, "studentNum1")
|
|
|
-
|
|
|
- newBody, err := json.Marshal(origin)
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- return newBody, nil
|
|
|
- },
|
|
|
- })
|
|
|
+func main() {
|
|
|
+ api.NewGateway()
|
|
|
+ defer api.DestroyGateway()
|
|
|
|
|
|
go func() {
|
|
|
- if err := app.Start(); err != nil {
|
|
|
+ if err := api.Start(); err != nil {
|
|
|
panic(err)
|
|
|
}
|
|
|
}()
|
|
|
|
|
|
defer func() {
|
|
|
- if err := app.Finish(); err != nil {
|
|
|
+ if err := api.Finish(); err != nil {
|
|
|
panic(err)
|
|
|
}
|
|
|
}()
|