|
|
@@ -1,6 +1,7 @@
|
|
|
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"
|
|
|
@@ -23,16 +24,32 @@ func main() {
|
|
|
PrefixRouter().
|
|
|
RegisterVersionedRouter("v1")
|
|
|
|
|
|
- prefixRootBinder := binding.NewBinder(app.ChooseRouter(api.RouterPrefix, ""), app.Infrastructure())
|
|
|
-
|
|
|
gw := gateway.NewGateway()
|
|
|
defer gateway.DestroyGateway(gw)
|
|
|
|
|
|
- gw.Redirect(prefixRootBinder, &gateway.PassThrough{
|
|
|
- HttpMethod: http.MethodGet,
|
|
|
- SimplePassThrough: &gateway.SimplePassThrough{
|
|
|
- RelativePath: "/version",
|
|
|
- ToBaseUrl: "http://localhost:31000/example/api",
|
|
|
+ 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)
|
|
|
+
|
|
|
+ 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
|
|
|
},
|
|
|
})
|
|
|
|