Template Modification
#
ScenarioImplement a uniformly formatted body accordingly, in the following format.
① The actual response data
tip
The code generated by go-zero
does not process it
#
PreparationWe go ahead and write a Response
method in the response
package under the project with module
as greet
, with a directory tree similar to the following.
The code is as follows
handler
template#
Modify the Replace the template with the following
① Replace with your real response
package name, for reference only
② Customized template content
tip
If there is no local ~/.goctl/api/handler.tpl
file, you can initialize it with the template initialization command goctl template init
#
Comparison- Before
- After
#
Comparison of response body- Before
- After
#
SummaryThis document only describes the process of customizing the template for the corresponding example of http, in addition to the following scenarios of customizing the template.
- model layer adds kmq
- model layer to generate the model instance of the option to be valid
- http customize the corresponding format ...