title: How can I compare struct data and interface data in Golang?
body: <p>I am trying to create a generic Binary Tree in Golang. How can I compare data from an interface and input data in the code? Here is an example of what I am trying to do. The comparison that is giving me trouble is this</p>
  
  <pre><code> } else if cur.data &lt; data {
  </code></pre>
  
  <p>-</p>
  
  <pre class="lang-golang prettyprint-override"><code>package DSAA
  
  type TreeNode struct {
      data interface{}
      right *TreeNode
      left *TreeNode
  }
  
  type BinarySearchTree struct {
      root *TreeNode
  }
  
  func BSTCreate() *BinarySearchTree {
      return &amp;BinarySearchTree{nil}
  }
  
  func (b *BinarySearchTree) Insert(cur TreeNode, data interface{}) *BinarySearchTree {
      if &amp;cur == nil {
          cur := &amp;TreeNode{data, nil, nil}
      } else if cur.data &lt; data {
          b = b.Insert(*cur.left, data)
      } else {
          b = b.Insert(*cur.right, data)
      }
      return b
  }
  </code></pre>