1、package ... :code in directory ... expects import "..."
解决方案
在GOPATH/src下新建"go.uber.org/zap"/"golang.org/x/net/websocket"文件夹,然后将代码拷贝过去。引用包也改为:
import (
"go.uber.org/zap"
''golang.org/x/net/websocket''
)
2、“invalid character '\x00' after top-level value”
发现json字节里面有空字节,
正确的解码方式应该是:
json.Unmarshal(buf[:n], &msg)
//读取一个客户端发送过来的数据
request := make([]byte, 1024)
read_len, err := conn.Read(request)
request_right := request[:read_len]
j := new(Json)
err := j.UnmarshalJSON(request) // not working
如果实际读取到的数据长度 < 缓冲区的长度:1024,此时json反序列化就会出现上述错误,
ReadFromUDP
can return a packet of any size, from 1 to 2000 bytes, you need to reslice your buffer using the number of bytes actually read.
RealReadLen, _, err = conn.ReadFromUDP(request )
ReadFromUDP
可以返回实际上从IO口读取到的字节数。
3、向HDFS提交数据错误:
SendFile2Hdfs fail: Put http://worker5:9864/webhdfs/v1/lfdataanalysis/basicdata/rxTimeData_ant0_00256016_2019-12-11_14-57-51.dat?op=CREATE&user.name=hadoop&namenoderpcaddress=ns1&blocksize=134217728&buffersize=4096&createflag=&createparent=true&overwrite=true&permission=644&replication=3: dial tcp: lookup worker5 on 10.30.8.8:53: no such host。
错误原因:HDFS服务权限设置问题