Java's enums have usefull method 'valueOf(string)' what return const enum member by it name. Ex.
enum ROLE {
FIRST("First role"),
SECOND("Second role")
private final String label;
private ROLE(label String) {
this.label = label;
}
public String getLabel() {
return label;
}
}
// in other place of code we can do:
ROLE.valueOf("FIRST").getLabel(); // get's "First role"
This behavior usefull for, for example, after html form's select submits to server. We have string representation what need to convert into real enum.
Can someone tell, can golang do same behavior? Code examples are welcome.