title: How to create a generic function to unmarshal all types?
body: <p>I have a function below, and I would like to make it generic:</p>
  
  <pre><code>func genericUnmarshalForType1(file string) Type1 {
  
    raw, err := ioutil.ReadFile(file)
  
    if err != nil {
        fmt.Println(err.Error())
        os.Exit(1)
    }
  
    var type1 Type1
  
    json.Unmarshal(raw, &amp;type1)
  }
  </code></pre>
  
  <p>I would like to create a function that accepts Type1 or Type2 without the need to create a function per type. How can I do this?</p>