cloudwego / hertz

Go HTTP framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
5.28k stars 515 forks source link

零值字段在响应的时候为空 #1199

Closed qingyggg closed 3 weeks ago

qingyggg commented 1 month ago

Describe the Question 1.以下是我定义的接口类型: { "article": { 。。。。 "info": { "comment_count": 0, "dislike_count": 0, "is_favorite": true, "like_count": 0, "viewed_count": 0 } }, "status_code": 0, 。。。 } 以下是实际的返回值: { "status_code": 0, "article": { "info": { "viewed_count": 2 }, } } Reproducible Code

Please construct a minimum complete and reproducible example for us to get the same error. And tell us how to reproduce it like how you send a request or send what request.

Expected behavior 我希望hertz在处理接口的时候,响应所有的字段,及时是某些字段是go语言的零值,我也希望它有一个结果(0,"",nil),这样子我好在前端做处理,所以,我应该怎么设置才能达到预期的效果 Screenshots

If applicable, add screenshots to help explain your question.

Hertz version:

github.com/cloudwego/hertz v0.9.3 // indirect Environment: GO111MODULE='on' GOARCH='amd64' GOBIN='' GOCACHE='/home/wen/.cache/go-build' GOENV='/home/wen/.config/go/env' GOEXE='' GOEXPERIMENT='' GOFLAGS='' GOHOSTARCH='amd64' GOHOSTOS='linux' GOINSECURE='' GOMODCACHE='/home/wen/.gvm/pkgsets/go1.22/global/pkg/mod' GONOPROXY='' GONOSUMDB='' GOOS='linux' GOPATH='/home/wen/.gvm/pkgsets/go1.22/global' GOPRIVATE='' GOPROXY='https://proxy.golang.org,direct' GOROOT='/home/wen/.gvm/gos/go1.22' GOSUMDB='sum.golang.org' GOTMPDIR='' GOTOOLCHAIN='auto' GOTOOLDIR='/home/wen/.gvm/gos/go1.22/pkg/tool/linux_amd64' GOVCS='' GOVERSION='go1.22.0' GCCGO='gccgo' GOAMD64='v1' AR='ar' CC='gcc' CXX='g++' CGO_ENABLED='1' GOMOD='/home/wen/workspace/qingyggg/blog_server/go.mod' GOWORK='' CGO_CFLAGS='-O2 -g' CGO_CPPFLAGS='' CGO_CXXFLAGS='-O2 -g' CGO_FFLAGS='-O2 -g' CGO_LDFLAGS='-O2 -g' PKG_CONFIG='pkg-config' GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1289084898=/tmp/go-build -gno-record-gcc-switches' The output of go env.

Additional context

Add any other context about the question here.

FGYFFFF commented 1 month ago

可以查一下 json marshal 的行为,hertz 返回调用的 json.marshal 接口进行序列化

superly7 commented 3 weeks ago

https://www.cloudwego.io/zh/docs/hertz/tutorials/toolkit/command/ 用hz命令update的时候加上--unset_omitempty参数

qingyggg commented 1 week ago

好的谢谢你