title: Is the idiomatic way to create a Go struct field "alias" just a custom getter?
body: <p>I'm porting some Python code to Go, in an effort to learn the language. One of the things that's done in the python code is properties on class attributes that provide different aliases for member access. For example:</p>
  <pre class="lang-py prettyprint-override"><code>class Grid:
      def __init__(self, x, y):
          self.x = x
          self.y = y
  
      @property
      def row(self):
          return self.y
  
      @property
      def column(self):
          return self.x
  
  # Usage:
  a = Grid(5, 7)
  a.row == a.y      # True
  </code></pre>
  <p>This allows the user to choose which representation (<code>(row, column)</code> vs <code>(x, y)</code>) makes the most sense for a particular piece of code.</p>
  <p>When porting this class to Go, the most obvious solution is a struct:</p>
  <pre class="lang-golang prettyprint-override"><code>type Grid struct {
      X, Y int
  }
  </code></pre>
  <p>Main question: If I wanted to create field &quot;aliases&quot; for a struct, is the idiomatic way to just create getters? Or is there something else built into the language that I'm not aware of?</p>
  <p>I have found something called <a href="https://www.digitalocean.com/community/tutorials/how-to-use-struct-tags-in-go" rel="nofollow noreferrer">struct tags</a> I thing that's intended to solve a different problem.</p>
  <p>Using getters:</p>
  <pre class="lang-golang prettyprint-override"><code>type Grid struct {
      X, Y int
  }
  
  func (g *Grid) Row() int {
      return g.Y
  }
  
  func (g *Grid) Column() int {
      return g.X
  }
  
  // Usage
  func main() {
      g := Grid{5, 7}
      fmt.Println(&quot;%d&quot;, g.Row())
  }
  </code></pre>