Dependencies
After installing the tool sponge, execute the command to open the UI interface:
sponge run
Quickly create a web project
Enter the Sponge UI interface, click on the left menu bar 【SQL】→【Create web project】, fill in some parameters to generate the complete project code for the web service.
The web service code is mainly composed of commonly used libraries such as gin, gorm, go-redis, and also includes swagger documentation, test code, common service governance function code, build deployment scripts, etc.
Switch to the web directory and run the command:
# Generate swagger documentation
make docs
# Compile and start the web service
make run
Open http://localhost:8080/swagger/index.html in your browser to perform CRUD operations on the table.
Batch add CRUD code embedded in web service
Enter the Sponge UI interface, click on the left menu bar 【Public】→【Generate handler CRUD code】, select any number of tables to generate code, then move the generated CRUD code to the web service directory to complete batch addition of CURD interfaces in the web service without changing any code.
Switch to the web directory and run the command:
# Generate swagger documentation
make docs
# Compile and start the web service
make run
Open http://localhost:8080/swagger/index.html in your browser to see the newly added CRUD interfaces.
This is the complete web service code generated from the above steps https://github.com/zhufuyi/sponge_examples/tree/main/1_web-gin-CRUD
Click to view detailed web service development documentation https://go-sponge.com/web-development-mysql
Top comments (0)