title: How to mock a function to get a different return value in golang
body: <p>I'm writing unit tests for a function that I developed in golang. Here is the code snippet:</p>
  
  <pre><code>func myFunc () {
      //there is some code
      err := json.Unmarshal (a, &amp;b)
      if err != nil {
          //handle error    
      }
  
      //there is some more code
  
      err := json.Unmarshal (c, &amp;d)
      if err != nil {
          //handle error    
      }
  }
  </code></pre>
  
  <p>Now I want to mock first unmarshal to return success and second unmarshal to return failure. In python, I see one similar post:
  <a href="https://stackoverflow.com/questions/24897145/python-mock-multiple-return-values">Python mock multiple return values</a></p>
  
  <p>But I cannot find one for golang. Can anyone please help me on this.</p>