title: How can I restrict value of variables in Golang?
body: <p>I know Go idiomatic don't have setter and getter. But I need to restrict value of variables in Go.</p>
  
  <p>I defined new type</p>
  
  <pre><code>type MyNewStringType string
  </code></pre>
  
  <p>And variables, that was defined as MyStringType, need to restrict value.</p>
  
  <p>Variables of MyStringType can have only 3 values:
  "Yes", "No", "I don't know"</p>
  
  <p>How can I do it in Golang?
  In Java, C++ I have setter and getter, but in Golang is not normal.</p>
  
  <p>I know, I can create</p>
  
  <pre><code>type MyNewStringType struct {
     Variable string
  }
  </code></pre>
  
  <p>and create </p>
  
  <pre><code>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")
    }
  </code></pre>
  
  <p>But I think it's wrong way. </p>