gobuffalo / envy

Envy makes working with ENV variables in Go trivial.
MIT License
156 stars 21 forks source link

Add goroutine safety warning. Tidy up mutexes. Return copy from Map #14

Closed robotlovesyou closed 6 years ago

robotlovesyou commented 6 years ago

This would possibly break existing code!

I can't come up with a way to make the Test() function goroutine safe. Even adding a Mutex exclusively for Test() won't work because it could still race with a goroutine calling other Getter/Setter functions. Instead I've added a warning to the documentation for the Test function which addresses #13

I've changed the mutex to an RWMutex since the map is safe for concurrent read, just not concurrent read/write. Assuming that most envy usage will be very read biased this should be worthwhile.

I've made sure there is a mutex around every function which mutates or reads the env (Except for the Temp() function)

Lastly, and this is likely to be the problematic part, I've altered Map to return a copy since it doesn't make sense (at least to me) to wrap it up with a Mutex inside envy but then just hand it over to external code which can read/write from/to it however it pleases.

stanislas-m commented 6 years ago

@markbates This one is approved, but not merged. :)

markbates commented 6 years ago

Thanks for the reminder @stanislas-m

Thanks @robotlovesyou

robotlovesyou commented 6 years ago

yw :)

Thanks for the awesome framework!