title: How to create a variable with needed type instead of type assertion
body: <p>I have a function which takes an interface, like this:</p>
  
  <pre><code>func method(data interface{})
  </code></pre>
  
  <p>.. because I need to process different structs which have common fields/methods. In this function I use <code>data</code> tens or hundreds of times, in different places. It's really unpleasant to add <code>switch a.(type) { case .. case ..</code> all the time.</p>
  
  <p>Is there a way to create a variable with just one <code>switch</code> with needed type and then just use this variable everywhere later? Something like:</p>
  
  <pre><code>var a .... // something here
  
  switch data.(type) {
  case *Struct1:
      a = data.(*Struct1)
  case *Struct2:
      a = data.(*Struct2)
  }
  
  // Continue with 'a' only
  a.Param = 15
  fmt.Println(a.String())
  </code></pre>