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)
- Pass variable in rout HOT 1
- Register tauri:// scheme (or allow custom schemes upstream?)
- please support get parms from Transfer-Encoding:compress-deflate
- unexpected EOF during install HOT 1
- sse panic on fasthttphandler HOT 1
- How does the gin close the log file? HOT 3
- Should we use url.PathUnescape instead of url.QueryUnescape when UnescapePathValues is true
- go get failed: The requested name is valid, but no data of the requested type was found HOT 1
- Attach Response Headers (or middlewares) to redirected requests (CORS issues) HOT 1
- Should context.GetRawData() also copy body to BodyBytesKey? HOT 3
- YAML BindBody should not parse JSON content HOT 1
- Gin do not support javascript ? HOT 5
- Does gin.Recovery() run before or after Group middleware? HOT 1
- How can i prevent a http connection to close HOT 3
- BasicAuth is not suitable for proxy auth
- Can't get status as expected from context.Status() HOT 1
- Gin Context implementation breaks context.Context contract HOT 4
- [Suggestions] Introducing an AI-powered robot to assist with daily issue and pull request (PR) tasks.
- Need c.JSON() response like behaviour for c.SSEvent() response for supporting first party clients like OpenAI SDK HOT 2
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.