Skip to content
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

Merged
merged 4 commits into from
Aug 14, 2024

Conversation

luborco
Copy link
Contributor

@luborco luborco commented Aug 12, 2024

No description provided.

@luborco luborco self-assigned this Aug 12, 2024
Michal Ližičiar added 2 commits August 12, 2024 11:37
w.WriteHeader(http.StatusInternalServerError)
}

fmt.Fprint(w, response)
Copy link
Contributor

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)
Copy link
Contributor

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
Copy link
Contributor

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.

opts protojson.MarshalOptions
}

func NewOptions(cfg *Config) Encoder {
Copy link
Contributor

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)

}
}

func (e Encoder) Format(m proto.Message) (string, error) {
Copy link
Contributor

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.

Copy link
Contributor

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)

@luborco luborco merged commit f8ae560 into main Aug 14, 2024
4 checks passed
@luborco luborco deleted the feature/add-emit-unpopulated-and-default-values branch August 14, 2024 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants