feat(random): use crypto/rand for random string generator#55
Merged
Conversation
Contributor
|
maybe https://github.com/labstack/echo/blob/e6b96f8873fed46e71e0d34cddb81c533167f954/middleware/util.go#L69 would be suitable here also. |
Contributor
Author
Thank you for the comment. I will take a look the link you mentioned and update the PR accordingly. |
Contributor
Author
|
@aldas I have updated the source code as you suggested. Please let me know what you think. |
This reverts commit 213dc71.
Contributor
Author
|
@aldas Hi, just wondering what is the progress for this PR? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current implementation for
randompackage relied on globally seeded value.If any other part of the programs call
rand.Seed, the string generate byrandompackage will also be affected.To fix this issue, instead of callingrand.Seedduring initialization,NewSourceis called and the return value is stored insideRandomstruct.I made changes by referring to the source code from the link below.
https://github.com/labstack/echo/blob/e6b96f8873fed46e71e0d34cddb81c533167f954/middleware/util.go#L69
I also did some benchmarks before and after the update.
Before
After (with sync.Mutex)
After (with sync.Pool)