Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
HHC26 opened this issue Feb 18, 2024 · 4 comments
Open

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

HHC26 opened this issue Feb 18, 2024 · 4 comments

Comments

@HHC26
Copy link

HHC26 commented Feb 18, 2024

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
Copy link

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
Copy link
Author

HHC26 commented Feb 23, 2024

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

  2. robust engineering design specifications
    eg:
    image
    This is the directory of my project, which can be referenced

  3. 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
Copy link

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
Copy link

guava-coder commented Feb 24, 2024

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",
		})
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants