Logo

dev-resources.site

for different kinds of informations.

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

Published at
4/20/2023
Categories
go
web
gin
Author
zhufuyi
Categories
3 categories in total
go
open
web
open
gin
open
Author
7 person written this
zhufuyi
open
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

gin Article's
30 articles in total
Favicon
Developing a Simple RESTful API with Gin, ginvalidator, and validatorgo
Favicon
Go's Concurrency Decoded: Goroutine Scheduling
Favicon
🚀 Building a RESTful API in Go: A Practical Guide
Favicon
A Deep Dive into Gin: Golang's Leading Framework
Favicon
Building a Blog API with Gin, FerretDB, and oapi-codegen
Favicon
How to enable hot reload in your Gin project
Favicon
Implementing an Order Processing System: Part 1 - Setting Up the Foundation
Favicon
Gin and router example
Favicon
How to Upload Images to AWS S3 with Golang
Favicon
Basic CRUD Operations Using Golang, Gin Gonic, and GORM
Favicon
Simplifying User Management with GIN and MongoDB
Favicon
Gin + Gorm Practical Guide, Implementing a Simple Q&A Community Backend Service in One Hour
Favicon
A Beginner-friendly Approach to Developing a REST API with Go, Gin and MSQL
Favicon
Cara menggunakan Cobra untuk menjalankan server Golang Gin
Favicon
A Beginner-friendly Approach to Developing a REST API with Go and Gin
Favicon
Easily build a simple and reliable ordering system in an hour using go efficiency tools
Favicon
Example 5, Automatically generate grpc gateway service project code, easy to achieve cross-service grpc calls
Favicon
Example 3, Automatically generate generic web service (gin) project code, increasing development efficiency by at least 1x
Favicon
Example 6, Build a simple golang e-commerce microservices framework step by step using tool
Favicon
Building a simple API with Golang using Gin-gonic
Favicon
Golang Web API: Project configuration management using Viper
Favicon
Golang Web API Course: Create starter project with a simple health check endpoint
Favicon
API validation in Gin: Ensuring Data Integrity in Your API
Favicon
Using the tool to complete the conversion of a community back-end single service to a microservice cluster in one day
Favicon
A secret weapon to improve the efficiency of golang development, a community backend service was developed in one day
Favicon
Play Microservices: Api-gateway service
Favicon
Set up a Stripe Checkout REST API (+ metadata) using Go and Gin Framework.
Favicon
Go: CRUD API using Gin Framework
Favicon
Example 1, Automatically generate a complete gin+gorm+redis+CRUD web service project without writing a line of Go code
Favicon
Not a Go LiveView developer yet? Try to guess what this code is doing, though.

Featured ones: