Location>code7788 >text

Reading notes for Building Distributed Applications with the Gin Framework: p52-p76

Popularity:316 ℃/2024-10-16 23:58:36

Learning Day 4 of Building Distributed Applications with the Gin Framework, p32-p76 Summary, 25 pages total.

I. Technical summary

point of knowledge (math.)

(1)iouti

The book uses the ioutil package to read JSON files, but since go 1.16, ioutil is no longer recommended and the os package should be used.

(2)() vs ()

When the data is already loaded into memory (e.g. a string,slice) then use (); if reading a file then use.

-swagger

Generate an API documentation flow using the go-swagger package:

(1) Installation

go install /go-swagger/go-swagger/cmd/swagger@latest

(2) Adding swagger to a function

/ swagger:route GET /recipes listRecipes
// Returns list of recipes
// ---
// produces:
// - application/json
// responses:
// '200':
// description: Successful operation
// ListRecipesHandler differrecipes,Because it's a query for all,So the name is in the plural here
func ListRecipesHandler(c *) {
	(, recipes)
}

(3) Generate documents

swagger generate spec -o ./

Note: You need to execute this command every time you add a comment to a function, otherwise the API documentation will not be updated.

(4) Starting API service

 swagger serve --no-open -F swager ./

Note: Since I am using WSL, I need to add --no-open, otherwise it will report webbrowser: can't open browser error and the service cannot start.

There are two styles of UI: Redoc and Swagger UI. the absence of "-F swagger" specifies that the UI style is Swagger UI.

Note: I personally feel that the book this way is more cumbersome and cumbersome, at the same time a large number of comments lead to a very uncomplicated code.

II. English summary

None, Chapter 2 has fewer vocabulary words overall, except for food names.

III. Other

None.

IV. References

1. Programming

(1) Mohamed Labouardy,《Building Distributed Applications in Gin》:/subject/35610349

2. English

(1) Etymology Dictionary:

(2) Cambridge Dictionary:

Welcome to search and follow: programmers (a_codists)