写点什么

Golang easyjson

用户头像
escray
关注
发布于: 2021 年 04 月 26 日
Golang easyjson

极客时间《Go 语言从入门到实践》学习笔记 13,题图来自网络


44 | easyjson


看了一眼 easyjson 生成的 go 文件,非常晦涩难懂,不过我猜,大概的意思是把原本需要反射才能做到事情,拆开了,平铺直叙,相当于是把一些工作提前准备好,以此来提高效率。


估计又过了两年,类似于 easyjson 这样的库更多了。


发现即使课程到了尾声,还有同学会遇到 GOPATH 的问题。


45 | HTTP 服务


抄了一遍代码,比较怀念 Rails 里面相对简单的 Router 机制,不知道 Go 语言是否有类似的框架。即使没有,估计很快也会有人写出来一个的。


有一个同学提问


http.HandleFunc("/", func(rw http.ResponseWriter,r *http.Request) {  fmt.Println("hello world")})
复制代码


为什么访问的时候会在命令控制台上打印两次?我也不是特别清楚,但应该是和浏览器的访问机制有关。


访问 127.0.0.1:8080 会打印两次;访问其他任何有路由的地址,都会打印一次;访问没有路由的空地址,打印一次


按照路由规则,定义了根目录的 "/" 之后,似乎是可以匹配任何路径的,在一定程度上部分解释了上面的问题,访问任何地址,都至少打印一次。


另外,浏览器会屏蔽掉一些细节,比如 404 访问,一般会以空白页展示,可以考虑采用


curl -i  127.0.0:8080
复制代码


来查看详细的 Response 头。


46 | 构建 RESTful 服务


抄了一遍代码,再抄一遍 Github 上的介绍


HttpRouter is a lightweight high performance HTTP request router (also called multiplexer or just mux for short) for go.


... this router supports variables in the routing pattern and matches against the request method. It also scales better.


The router is optimized for high performance and a small memory footprint. It scales well even with very long paths and  a large number of routes. A compressing dynamic trie (radix tree) structure is used for efficient matching.


前缀树

发布于: 2021 年 04 月 26 日阅读数: 14
用户头像

escray

关注

Let's Go 2017.11.19 加入

Let's Go,用 100 天的时间从入门到入职

评论

发布
暂无评论
Golang easyjson