gin-gonic / gin

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
https://gin-gonic.com/
MIT License
76.8k stars 7.92k forks source link

Will it be made into a more comprehensive framework later on? #3847

Open HHC26 opened 4 months ago

HHC26 commented 4 months ago

I quite like using gin, but everyone has their own style of directory for their favorite projects. If gin can have more unified conventions and standards, and create a more powerful project framework, more people should use it

My idea: 1.Quickly generate projects 2.Unified development style 3.……

Some features of this project are worth referencing, but it encapsulates too much, link: https://github.com/gogf/gf

guava-coder commented 4 months ago

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.

HHC26 commented 4 months ago

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:

  1. automatic codes generating for efficiency
  2. robust engineering design specifications
  3. convenient development CLI tool provide
  4. openAPIV3 documentation generating, automatically

  1. 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

    1. robust engineering design specifications eg: image This is the directory of my project, which can be referenced
  2. openAPIV3 documentation generating, automatically type LoginReq struct { g.Meta path:"/login" method:"post" sm:"login" Name string json:"user_name" summary:"" Password string json:"password" summary:"" } type LoginRes struct { Token string json:"token" } link: https://redocly.com/redoc/ image

guava-coder commented 4 months ago

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

guava-coder commented 4 months ago

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:

  1. Writing Unit test with testing package.
  2. 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...*/
    }
  1. 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",
        })
    }
}
HHC26 commented 1 month ago

I think you're talking about gin-swagger

The gin swagger is not easy to use, if Gin can call it, it will be easier to generate API documentation