Comments (4)
convenient development CLI tool provide
Gin has no official CLI tool, but the community makes several of them.
Here are some Gin CLI tools I found via Google search:
openAPIV3 documentation generating, automatically
I think you're talking about gin-swagger
from gin.
automatic codes generating for efficiency
If some codes are regularly used, you can write snippets for it. Some plugins from the editor also provide auto-complete for Go, such as Tabnine, CodeGeeX, etc...
However, most of the time, I will avoid snippets and AI generation code on backend code, to prevent bugs and bad performance issues.
There are many different ways to increase efficiency while writing Go, here are some tips:
- Writing Unit test with testing package.
- Using Generic to make reusable components
example:
type Data interface {
User
}
type User struct {
Id string
Name string
/*other fields...*/
}
func ReadAndHandleRequestBody[T Data](ctx *gin.Context, operation func(T)) {
/*your code...*/
}
- Using APIs provided by the framework
For example, when you handle HTTP response, you can use *gin.Context.JSON( )
and gin.H{ }
to simplify:
...
func (serv UserService) QueryById(ctx *gin.Context, id string) {
...
if err == nil {
ctx.JSON(http.StatusOK, gin.H{
"Response": "Found User",
"User": res,
})
} else {
ctx.JSON(http.StatusBadRequest, gin.H{
"Response": "User not found",
})
}
}
from gin.
As you said, every developer has their own style of directory for their favorite projects. Will you going to make every style in one framework?
Frameworks like Spring Boot and Laravel that use MVC design patterns and provide project generation. However, you need to understand MVC, and how the project configuration works. Do you need MVC and project generation whenever use gin?
I prefer gin to remain simple, you can start a project with a few .go and .mod files, and it is ok. Gin doesn't give you a unified convention, but you can decide at any time.
from gin.
As you said, every developer has their own style of directory for their favorite projects. Will you going to make every style in one framework?
Frameworks like Spring Boot and Laravel that use MVC design patterns and provide project generation. However, you need to understand MVC, and how the project configuration works. Do you need MVC and project generation whenever use gin?
I prefer gin to remain simple, you can start a project with a few .go and .mod files, and it is ok. Gin doesn't give you a unified convention, but you can decide at any time.
I also agree with what you said ,but I also believe that these features are quite good,
eg:
- automatic codes generating for efficiency
- robust engineering design specifications
- convenient development CLI tool provide
- openAPIV3 documentation generating, automatically
-
automatic codes generating for efficiency and 3. convenient development CLI tool provide
gin gen ctrl, gin gen dao , gin gen service ……
eg:
gin gen COMMAND [OPTION]
COMMAND
ctrl parse api definitions to generate controller/sdk go files
dao automatically generate go files for model/
service parse struct and associated functions from packages to generate service go file -
robust engineering design specifications
eg:
This is the directory of my project, which can be referenced -
openAPIV3 documentation generating, automatically
type LoginReq struct {
g.Metapath:"/login" method:"post" sm:"login"
Name stringjson:"user_name" summary:""
Password stringjson:"password" summary:""
}
type LoginRes struct {
Token stringjson:"token"
}
link: https://redocly.com/redoc/
from gin.
Related Issues (20)
- custom time.Time type can not use bindQuery get a value. HOT 3
- configure server parameters HOT 1
- The binding:"required" tag does not seem to work for struct types HOT 3
- Is there a way to preserve order in JSON on response? HOT 1
- redirect is not success HOT 1
- I want to use shouldmindbodywith first and then use formafile, but it doesn't work right now HOT 3
- Extend the routing tree entry
- Transparent decompression for gzip, deflate, etc? HOT 1
- Custom time.Time type can not use bindQuery get a value 2 HOT 2
- http: response.Write on hijacked connection from github.com/gin-gonic/gin.(*responseWriter).Write (response_writer.go:83) HOT 1
- Suggestion: Move Print Debug to Run() functions? HOT 7
- AbortWithStatusJSON doesn't abort context HOT 2
- I translated `tree.go` into java
- GetUint and GetUint64 wrong return HOT 1
- Multipart form-data request with empty key for single file upload
- gin with golang 1.21, 1.22 DATA RACE
- gin detects `DATA RACE` with Go1.21, Go1.22 HOT 7
- Please consider remove github.com/bytedance/sonic from dependencies HOT 4
- send response from middleware, continue to execute handler chain HOT 3
- StringToBytes is slower than the raw convertion
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gin.