Skip to content

Comments

sample#3

Open
whisk wants to merge 1 commit intomainfrom
sample/code-reviews
Open

sample#3
whisk wants to merge 1 commit intomainfrom
sample/code-reviews

Conversation

@whisk
Copy link
Owner

@whisk whisk commented Dec 23, 2025

No description provided.

@@ -0,0 +1,3 @@
sample
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will panic if the slice is empty.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log messages already have timestamps, no need to write it additionally.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idiomatic way is to accept interfaces (io.Reader in this case), not concrete types.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may have a long list of associated nodes (> 10000), and it will exceed the response limit. I suggest truncating it to the first 100, as we don't really need all of them here.

@whisk whisk force-pushed the sample/code-reviews branch from baa32e7 to a399532 Compare December 23, 2025 12:17

import "net/http"

var data = []byte{
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: data is too ambiguous. userRequestPayload?


func sample() []byte {
var method string
if method == http.MethodGet {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: switch-case may be more readable than multiple if-else here.

@whisk whisk force-pushed the sample/code-reviews branch from a399532 to 7c2ca73 Compare December 23, 2025 12:27
return nil
}

func (u *User) BillingAddress() string {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning an empty string here may hide errors. What do you think about returning (string, error)?

@@ -0,0 +1,3 @@
sample
sample
sample
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You forgot to make this thread-safe.

Copy link
Owner Author

@whisk whisk Dec 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the first time I see you are ignoring errors. Why?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is literally the slowest way to concatenate strings.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not thread-safe and may cause a race when called concurrently.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ignored error may lead to invalid configuration if the config file is not found.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This allocates memory on each iteration; using strings.Builder would avoid that.

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.

1 participant