title: Any better way to check endianness in Go
body: <p>I am writing a small program to check the endianness using Go:</p>
  <pre><code>var i int = 0x0100
  ptr := unsafe.Pointer(&amp;i)
  if 0x01 == *(*byte)(ptr) {
      fmt.Println(&quot;Big Endian&quot;)
  } else if 0x00 == *(*byte)(ptr) {
      fmt.Println(&quot;Little Endian&quot;)
  } else {
      // ...
  }
  </code></pre>
  <p>I <code>import &quot;unsafe&quot;</code> package to convert <code>*int</code> to <code>*byte</code>.
  But as mentioned in <a href="https://golang.org/pkg/unsafe/" rel="noreferrer">https://golang.org/pkg/unsafe/</a>:</p>
  <blockquote>
  <p>Package unsafe contains operations that step around the type safety of Go programs.</p>
  <p>Packages that import unsafe may be non-portable and are not protected by the Go 1 compatibility guidelines.</p>
  </blockquote>
  <p>Is there a better way to determine endianness, or do I have to use unsafe package?</p>