-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add possibility enable emit unpopulated and default values. #6
Add possibility enable emit unpopulated and default values. #6
Conversation
…eature/add-emit-unpopulated-and-default-values
pkg/transport/transport.go
Outdated
w.WriteHeader(http.StatusInternalServerError) | ||
} | ||
|
||
fmt.Fprint(w, response) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using of fmt
when writing HTTP response body. Use io.Copy
, io.WriteString()
or w.Write()
.
response, err := rc.Encoder.Format(rpcResponse) | ||
if err != nil { | ||
logger.ErrorContext(r.Context(), jErrors.Details(jErrors.Trace(err))) | ||
w.WriteHeader(http.StatusInternalServerError) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing return
README.md
Outdated
@@ -40,6 +40,8 @@ Usage of ./grpc-rest-proxy: | |||
--transport.http.server.gracefulTimeout duration graceful timeout (default 5s) | |||
--transport.http.server.readHeaderTimeout duration read header timeout (default 5s) | |||
--transport.http.server.readTimeout duration read timeout (default 10s) | |||
--service.jsonencoder.emitUnpopulated emit unpopulated fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add more detailed description for new cli flags. Imagine user who is using this cli app for the first time.
pkg/service/jsonencoder/encoder.go
Outdated
opts protojson.MarshalOptions | ||
} | ||
|
||
func NewOptions(cfg *Config) Encoder { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rename NewOptions()
to New()
.
Compare
encoder := jsonencoder.NewOptions(cfg)
vs
encoder := jsonencoder.New(cfg)
pkg/service/jsonencoder/encoder.go
Outdated
} | ||
} | ||
|
||
func (e Encoder) Format(m proto.Message) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Change return value to ([]byte, error)
. This way returned value of []byte
can be used to write HTTP response body in w.Write()
without need to convert []byte
to string
and then back to []byte
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional: Rename from Format
to Encode
. The name of struct is Encoder
. Encoder is used for encoding. Formatter is used for formatting.
Compare
jsonResponse, err := jsonEncoder.Format(protoResponse)
with
jsonResponse, err := jsonEncoder.Encode(protoResponse)
No description provided.