title: building a dynamic query in mysql and golang
body: <p>How can I build a dynamic query depending on the parameters that I get?</p>
  
  <p>This example is stupid and the syntax is wrong but you will get the idea of what I want.</p>
  
  <p>I guess that I need to add a slice of variables to the end of the query.</p>
  
  <p>I know how to do it in PHP, but not in golang.</p>
  
  <pre><code>db := OpenDB()
  
  defer db.Close()
  
  var filter string
  
  if name != "" {     
  filter = filter " AND name = ?" 
  
  }
  
  if surname != "" {  
  filter = filter + " AND surname = ?"
  
  }
  
  if address != "" {  
  filter =  filter + " AND address = ?" 
  
  }
  
  err = db.Query("SELECT id FROM users WHERE login = ?" +
  filter, login)
  </code></pre>