On Thu, 7 Nov 2019 02:58:17 -0800 (PST)
bsr <bsr...@gmail.com> wrote:

> Is there a way I can prevent this behavior.
> I am using Status like an enum, and only predefined status values should be 
> allowed.

You cannot statically prevent someone from willfully assigning
to a variable of accessible type (eg. a function call parameter).
If you're just after sanity check there are many ways.

At runtime you can eg. use a map: https://play.golang.org/p/5rwJLFpU3a4

For compile time - you can use stringer tool to generate numerical constants 
mapped to strings.

hope this helps, 

-- 
Wojciech S. Czarnecki
 << ^oo^ >> OHIR-RIPE

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/20191110183714.706237b4%40zuzia.

Reply via email to