Article Directory
Utility functions, error handling, and middleware
Now you will find that you can write a large number of interfaces easily and freely: you can even write hundreds of interfaces a day if you want!
But when you build your application brutally like this, you always feel a little uncomfortable: you have to write a lot of sums, c.JSON()
and gin.H{}
almost always check at BadRequest
the beginning of each time . Although it is actually an error, we just returned. It's just a string.
In the next few subsections, we will make a little bit of 重构
our code again .
4.1 Utility functions: reuse your code snippets
First of all, we need to know what our first purpose is: so that we don’t have to handler
write inc.JSON()