guys!
I know golang idiomatic don't have setter and getter. But I need to restrict value of variables in Golang.
I defined new type
type MyNewStringType string
And variables, that was defined as MyStringType, need to restrict value.
Variables of MyStringType can have only 3 values: "Yes", "No", "I don't know"
How can I do it in Golang? In Java, C++ I have setter and getter, but in Golang is not normal.
I know, I can create
type MyNewStringType struct {
Variable string
}
and create
func(m *MyNewStringType) SetVariable(newVar string) error {
if newVar == "Yes" || newVar == "No" || newVar == "I don't know" {
m.Variable = newVar
return nil
} else {
return errors.New("Wrong value")
}
But I think it's wrong way.