提交最新的gateway 支持通用的response map返回
This commit is contained in:
parent
f7efb6faf3
commit
889b25edef
2
go.mod
2
go.mod
|
@ -47,4 +47,4 @@ require (
|
|||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
replace fusen-basic v0.0.0 => gitee.com/fusenpack/fusen-basic v0.0.5-0.20231116042329-f02917634c5e
|
||||
replace fusen-basic v0.0.0 => gitee.com/fusenpack/fusen-basic v0.0.5-0.20231116081152-8b986d7e7d8d
|
||||
|
|
4
go.sum
4
go.sum
|
@ -1,6 +1,6 @@
|
|||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
gitee.com/fusenpack/fusen-basic v0.0.5-0.20231116042329-f02917634c5e h1:7AP0afu7/BedGvbl8yqVUCB1GuDYsO/omHZ8Qlu3gGw=
|
||||
gitee.com/fusenpack/fusen-basic v0.0.5-0.20231116042329-f02917634c5e/go.mod h1:Zw6gt/0VwNmtG2Boqmo8+5H5AVuWsIVgCgp1ilkRyao=
|
||||
gitee.com/fusenpack/fusen-basic v0.0.5-0.20231116081152-8b986d7e7d8d h1:pT0RRNVq3cmRvgifnmI3RX5pp5zGImqRViefBPDu1OQ=
|
||||
gitee.com/fusenpack/fusen-basic v0.0.5-0.20231116081152-8b986d7e7d8d/go.mod h1:Zw6gt/0VwNmtG2Boqmo8+5H5AVuWsIVgCgp1ilkRyao=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
|
||||
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
|
||||
|
|
2
proto
2
proto
|
@ -1 +1 @@
|
|||
Subproject commit 15818aeb2164a825e2003ff5d931d04c8a80e71a
|
||||
Subproject commit 8148328349962a10354363537e4ac9659892ea0a
|
|
@ -21,10 +21,5 @@ func AutoRegisterHandler(ctx context.Context, mux *runtime.ServeMux, opts ...grp
|
|||
return err
|
||||
}
|
||||
|
||||
err = service.RegisterInfoHandlerClientNacos(ctx, mux, opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"fusen-basic/basic"
|
||||
"fusen-gateway/gen/go/service"
|
||||
"net/http"
|
||||
"regexp"
|
||||
|
||||
|
@ -21,7 +22,16 @@ func (m *EmptyMarshaler) Marshal(v interface{}) ([]byte, error) {
|
|||
return nil, nil
|
||||
}
|
||||
|
||||
var fsProtoJSON = &runtime.JSONPb{
|
||||
var fsDefaultProtoJSON = &runtime.JSONPb{
|
||||
MarshalOptions: protojson.MarshalOptions{
|
||||
EmitUnpopulated: true,
|
||||
},
|
||||
UnmarshalOptions: protojson.UnmarshalOptions{
|
||||
DiscardUnknown: true,
|
||||
},
|
||||
}
|
||||
|
||||
var fsProtoDataJSON = &runtime.JSONPb{
|
||||
MarshalOptions: protojson.MarshalOptions{
|
||||
EmitUnpopulated: true,
|
||||
},
|
||||
|
@ -35,10 +45,21 @@ var codeRE = regexp.MustCompile(`(?i)"code"\s*:\s*(\d+)`)
|
|||
func WriteFusenResponse(fsHeader string, w http.ResponseWriter, resp proto.Message) error {
|
||||
w.WriteHeader(200)
|
||||
var buf = bytes.NewBufferString(fsHeader[:len(fsHeader)-1] + ",")
|
||||
rdata, err := fsProtoJSON.Marshal(resp)
|
||||
if err != nil {
|
||||
return err
|
||||
var rdata []byte
|
||||
var err error
|
||||
|
||||
if customResp, ok := resp.(*service.Response); ok {
|
||||
rdata, err = protojson.Marshal(customResp.GetData())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
rdata, err = protojson.Marshal(resp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
buf.WriteString(`"data":`)
|
||||
buf.Write(rdata)
|
||||
buf.WriteString(`}`)
|
||||
|
|
Loading…
Reference in New Issue
Block a user