DEV Community

zhuyasen
zhuyasen

Posted on • Edited on

Example 1, Automatically generate a complete gin+gorm+redis+CRUD web service project without writing a line of Go code

Dependencies

  • Import sql into mysql services.
  • Installation tool sponge.

After installing the tool sponge, execute the command to open the UI interface:

sponge run
Enter fullscreen mode Exit fullscreen mode

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.

Image description

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  
Enter fullscreen mode Exit fullscreen mode

Open http://localhost:8080/swagger/index.html in your browser to perform CRUD operations on the table.

Image description

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.

Image description

Switch to the web directory and run the command:

# Generate swagger documentation  
make docs  

# Compile and start the web service  
make run  
Enter fullscreen mode Exit fullscreen mode

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

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Retry later