go错误总结(27条)

1、undefined: apppen

没有此方法,请检查语法或者单词是否正确

2、m3 redeclared in this block previous declaration at .\utils.go:308:2

此方法或者变量没有使用,具体在308行

3、missing return at end of function

此方法缺少return返回或者结束标识符

4、s6 declared but not used

s6变量没有使用

5、err declared but not used b declared but not used

err和b没有使用

6、Println call has possible formatting directive %T

Println 调用的格式指令存在问题

7、exported function GmyFunc should have comment or be unexported

声明你写的代码不符合规范

8、(func(a, b int) int literal) (value of type func(a int, b int) int) is not used

此函数没有被调用

9、死锁与 goroutine 泄露

检查:goroutine 栈图定位死锁函数方法

解决方法:严禁在一行代码内对同一个变量产生两次写行为;严禁在一行代码内对同一个变量产生既写又读的行为; 严禁在锁内执行被锁对象的行为函数。

10、sync.Pool

sync.Pool 的本质是用来减轻 gc 负担 ;将它当做一个对象缓冲池并不合适:对象何时释放,用户是无法释放的。
虽然 sync.Pool 把对象存入其缓冲池时可以做到无锁,但是取值的时候可能碰到锁竞争的问题 ;所以可能对性能提升并没有多大帮助。

11、expected ‘IDENT’, found 'func’

错误:

func oper(a, b int, func func(int, int) int) int {
}
1
2
解决:

func oper(a, b int, fun func(int, int) int) int {
}
1
2
12、Println arg fun is a func value, not called

fun是一个func值,未调用

13、golang.org/x/crypto is not in your go.mod fil

cd $gopath/src/ 如果没有golang/x 创建mkdir -p golang/x,然后cd golang/x
使用git进行下载 git clone https://github.com/golang/crypto.git
也可以:git clone --depth=1 https://github.com/golang/xxx.git

14、Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.

Println格式使用其操作数的默认格式,并写入标准输出。操作数之间总是加上空格,并追加换行符。它返回写入的字节数和遇到的任何写入错误

15、illegal character U+FF0C ','

标点符号错误

16、exported type Userinfo should have comment or be unexported

没有使用Userinfo结构体

17、sql: expected 0 arguments, got 1

会报无效字符

18、too many arguments compiler

编译器参数太多

19、expected ‘package’, found 'const’

请检查代码依赖或者mod.go是否错误

20、possible misuse of unsafe.Pointerunsafeptr

指针存储不安全

21、首字母大写是公有的 Echo,首字母小写是私有的 echo

22、 don’t use underscores in Go names; var w_content should be wContent

不符合命名规范

23、ReadLine is a low-level line-reading primitive. Most callers should use ReadBytes(’\n’) or ReadString(’\n’) instead or use a Scanner. ReadLine tries to return a single line, not including the end-of-line bytes. If the line was too long for the buffer then isPrefix is set and the beginning of the line is returned. The rest of the line will be returned from future calls. isPrefix will be false when returning the last fragment of the line. The returned buffer is only valid until the next call to ReadLine. ReadLine either returns a non-nil line or it returns an error, never both. The text returned from ReadLine does not include the line end ("\r\n" or “\n”). No indication or error is given if the input ends without a final line end. Calling UnreadByte after ReadLine will always unread the last byte read (possibly a character belonging to the line end) even if that byte is not part of the line returned by ReadLine.

解决:

line, err := buf.ReadLine('\n') 改成 line, err := buf.ReadString('\n') 或者 line, err := buf.ReadBytes('\n')

24、内部有缓冲区的读取 goroutine 很昂贵

解决:

netpoll(epoll,kqueue); 重用缓冲区。

25、内部有缓冲区的写入 goroutine 很昂贵

解决:

必要时启动 goroutine; 重用缓冲区。

26、随着大量的连接,netpoll 不起作用

解决:

重复使用 goroutines 并限制其数量

27、net/http不是处理升级到WebSocket的最快方法

解决:

在裸TCP连接上使用零拷贝升级

posted @ 2022-03-16 15:16  天纯蓝  阅读(509)  评论(0编辑  收藏  举报