《使用Gin框架构建分布式应用》阅读笔记:p52-p76

《用Gin框架构建分布式应用》学习第4天,p32-p76总结,总计25页。

一、技术总结

1.Go知识点

(1)iouti

书上使用ioutil包读取JSON文件,但是从go 1.16 开始,不再推荐使用ioutil,应该使用os 包。

(2)json.Unmarshal() vs json.NewDecoder()

当数据已经被加载到内存中了(例如一个string,slice),那么使用json.Unmarshal();如果是读取文件,那么使用json.NewDecoder。

2.go-swagger

使用 go-swagger包生成API文档流程:

(1)安装

go install github.com/go-swagger/go-swagger/cmd/swagger@latest

(2)给函数添加swagger

/ swagger:route GET /recipes  listRecipes
// Returns list of recipes
// ---
// produces:
// - application/json
// responses:
// '200':
// description: Successful operation
// ListRecipesHandler 差下recipes,因为是查询所有,所以名称这里用的是复数
func ListRecipesHandler(c *gin.Context) {
	c.JSON(http.StatusOK, recipes)
}

(3)生成文档

swagger generate spec -o ./swagger.json

注:每次给函数添加注释后都需要执行该命令,否则API文档不会更新。

(4)启动API服务

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

注:因为本人使用的是WSL,所以需要添加–no-open,否则报webbrowser: can’t open browser错误,服务无法启动。

UI有两种风格:Redoc和 Swagger UI。上没“-F swagger”指定了UI风格为Swagger UI。

注:个人觉得书上这种方式比较麻烦且繁琐,同时大量的注释导致代码非常不简洁。

二、英语总结

无,第二章除了食物名,整体来说生词比较少。

三、其它

无。

四、参考资料

1. 编程

(1) Mohamed Labouardy,《Building Distributed Applications in Gin》:https://book.douban.com/subject/35610349

2. 英语

(1) Etymology Dictionary:https://www.etymonline.com

(2) Cambridge Dictionary:https://dictionary.cambridge.org

在这里插入图片描述

欢迎搜索及关注:编程人(a_codists)

Module 1, Learning Go Web Development, starts off with introducing and setting up Go before you move on to produce responsive servers that react to certain web endpoint. You will then implement database connections to acquire data and then present it to our users using different template packages. Later on, you will learn about sessions and cookies to retain information before delving with the basics of microservices. By the end of this module, we will be covering the testing, debugging, and the security aspect. Module 2, Go Programming Blueprints, has a project-based approach where you will be building chat application, adding authentication, and adding your own profile pictures in different ways. You will learn how Go makes it easy to build powerful command-line tools to find domain names before building a highly scalable Twitter polling and vote counting engine powered by NSQ and MongoDB. Later on it covers the functionalities of RESTful Data Web Service API and Google Places API before you move on to build a simple but powerful filesystem backup tool for our code projects. Module 3, Mastering Concurrency in Go, introduces you to Concurrency in Go where you will be understanding the Concurrency model and developing a strategy for designing applications. You will learn to create basic and complex communication channels between our goroutines to manage data not only across single or multithreaded systems but also distributed systems. Later on you will be tackling a real-world problem, that is, being able to develop a high performance web server that can handle a very large volume of live, active traffic. You will then learn how to scale your application and make it capable of being expanded in scope, design, and/ or capacity. It will then focus on when and where to implement concurrent patterns, utilize parallelism, and ensure data consistency. At the end of this module, we will be logging and testing concurrency before we finally look at the best practices on how to implement complicated and advanced techniques offered by Go.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值