Giter VIP home page Giter VIP logo

Comments (4)

guava-coder avatar guava-coder commented on April 27, 2024 1

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.

guava-coder avatar guava-coder commented on April 27, 2024 1

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

from gin.

guava-coder avatar guava-coder commented on April 27, 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.

from gin.

HHC26 avatar HHC26 commented on April 27, 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

from gin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.