-
Notifications
You must be signed in to change notification settings - Fork 3
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
go #9
Comments
https://go101.org/article/channel-closing.html 关闭channel的方法 |
限制goroutine的数量
|
grpc 调试工具(类似postman之于http) |
go mod 系列博客阅读笔记 https://blog.golang.org/using-go-modules
|
goroutine 闭包如果不通过传参的方式使用指针,在for循环中,因为指针会被赋值,是共享的,可能会导致读到了更新过的值。通过参数传递的话,就能够保证每个 goroutine 用了不同的指针。
|
https://blog.chewxy.com/2018/03/18/golang-interfaces/ 从使用者定义interface |
https://blog.golang.org/laws-of-reflection A variable of interface type stores a pair: the concrete value assigned to the variable, and that value's type descriptor. To be more precise, the value is the underlying concrete data item that implements the interface and the type describes the full type of that item. |
github.com/cweill/gotests/gotests
自动生成单元测试模板 |
The convention in the Go libraries is that even when a package uses panic internally, its external API still presents explicit error return values. |
An interface value is nil only if the V and T are both unset, (T=nil, V is not set), In particular, a nil interface will always hold a nil type. If we store a nil pointer of type *int inside an interface value, the inner type will be *int regardless of the value of the pointer: (T=*int, V=nil). Such an interface value will therefore be non-nil even when the pointer value V inside is nil. interface只有type和value同时为nil,才 ==nil |
|
Go has no 'reference types' |
golang中string底层是通过byte数组实现的。中文字符在unicode下占2个字节,在utf-8编码下占3个字节,而golang默认编码正好是utf-8。 |
https://golang.org/pkg/net/http/#Client.Do
这种方式是ok的,不必考虑resp为非nil的情况(出现重定向错误),这种情况下body已经被close |
src/runtime/HACKING.md The scheduler's job is to match up a G (the code to execute), an M All |
打印结构体
%v``%+v``%#v
的区别针对结构体
%v 打印字段的值
%+v 打印字段的名字和字段的值
%#v 按照go中结构体的格式打印(打印结构体的名字,字段的名字和值)
如果字段是指针,值就是指针地址。
可以给结构体实现一个 String() string方法自定义打印的格式(从而打印指针对应的内容)。对%v和%+v生效,对%#v不生效。
实现了String()string 意味着实现了fmt.Stringer。fmt包中
%v
和%+v
会检查参数实现了error或者Stringer,从而调用errror()或者String()。%#v
则需要实现 GoString()string 方法来自定义。实现 fmt.Formatter 可做到更加灵活的格式控制。github.com/pkg/errors 就是用这种方式输出调用栈。可获取到 fmt.State 进行写,verb 判断占位符。
The text was updated successfully, but these errors were encountered: