title: How to test Gin-gonic controller properly?
body: <p>I'm learning golang by using Gin-gonic as http handler framework. I have a controller for an endpoint which makes operations with my own <code>Email</code> struct as following:</p>
  <pre class="lang-golang prettyprint-override"><code>func EmailUserVerification(c *gin.Context) {
      var input validators.EmailUserVerificationValidator
      if err := c.ShouldBindJSON(&amp;input); err != nil {
          c.JSON(http.StatusBadRequest, gin.H{&quot;error&quot;: err.Error()})
          return
      }
  
      email := models.Email{
          To:       input.To,
          Subject:  input.Subject,
          Template: &quot;user_verification.html&quot;,
          TemplateData: notices.EmailUserVerificationTemplateData{
              Name:             input.Name,
              VerificationLink: input.VerificationLink,
          },
          Sender: models.NewEmailSMTPSender(input.From),
      }
  
      if err := email.Deliver(); err != nil {
          panic(err)
      }
      c.JSON(http.StatusCreated, nil)
  }
  </code></pre>
  <p>Struct <code>Email</code> is already test, nevertheless I do not know how to test this method properly. how it is supposed <code>Email</code> struct to be mocked here?</p>
  <p>I registered the handler as gin-gonic documentation say:</p>
  <pre class="lang-golang prettyprint-override"><code>router.POST(&quot;/emails/users/verify&quot;, controllers.EmailUserVerification)
  </code></pre>
  <p>Maybe could I inject an Email interface in the handler? if it is the case, how can I inject it?</p>
  <p>Thanks in advance ^^</p>