golang-petname icon indicating copy to clipboard operation
golang-petname copied to clipboard

move init() from the shared package into the CLI

Open bfallik opened this issue 7 years ago • 5 comments

Hi,

We'd like to use your library to generate nonces but I'm concerned about the init() function that's included in petname.go. This init() will be called on startup and could conflict with other calls to rand.Seed().

In our case we have some code to alternate between a specific seed in order to repeat a test run and time.Now().UTC().UnixNano() for psuedo-random behavior.

Would you be open to simple PR to move the init() into https://github.com/dustinkirkland/golang-petname/blob/master/cmd/petname/main.go? This shouldn't affect the behavior of the petname utility but it will make it easier for us to reuse the library.

Thanks, brian

bfallik avatar Apr 04 '17 20:04 bfallik

I should add that another approach is to modify this package to use it's own rand.Rand object instead of the global one.

bfallik avatar Apr 04 '17 20:04 bfallik

+1, that's a fine approach. Just go ahead and move the seed to the main.go. That's definitely where it belongs. Thanks!

dustinkirkland avatar Apr 07 '17 17:04 dustinkirkland

Cool. PR at https://github.com/dustinkirkland/golang-petname/pull/5.

bfallik avatar Apr 07 '17 20:04 bfallik

Great, thanks. I've merged it and pushed trunk. I'll release 2.7 very soon.

Cheers! Dustin

:-Dustin @dustinkirkland

On Fri, Apr 7, 2017 at 3:25 PM, Brian Fallik [email protected] wrote:

Cool. PR at #5 https://github.com/dustinkirkland/golang-petname/pull/5.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/dustinkirkland/golang-petname/issues/4#issuecomment-292642870, or mute the thread https://github.com/notifications/unsubscribe-auth/AAzMhkRqM7f_sxVG5cubLdu7WUIIrz7Wks5rtpu8gaJpZM4MzZ3E .

dustinkirkland avatar Apr 10 '17 15:04 dustinkirkland

How is this versioned for users of the package?

This is a breaking change to API of the petname Go package. The "blessed" Go way is to never change the API, but the more pragmatic approach is to version with semver and tag releases in Github. That way tools like glide can pick up the versions.

davidbanham avatar Jun 21 '17 05:06 davidbanham