【发布时间】:2018-06-04 04:17:30
【问题描述】:
我在 Go(在 OSX 上)中使用 this library 与 Windows DNS 服务器交互。
运行下面的 sn-p 时,我收到一个关于空终止符的错误。
$ ~/go/bin/winrm-dns-client create -d domain.com -n node-0 -t A -v 10.90.61.30
2018/06/03 12:40:22 Error creating DNS record: Reading record: Reading record: Unmarshalling response: Unmarshalling json: invalid character '\x00' after array element
我怀疑当辅助方法调用 sprintf 将 json 响应连接到数组中时,添加了一个空终止符 here。
但是,即使添加了如下所示的bytes.Trim... 我仍然收到空终止符错误,而且空终止符似乎仍然存在...
func unmarshalResponse(resp string) ([]interface{}, error) {
var data interface{}
byteRespTrim := []byte(resp)
fmt.Print("found a null terminator at -- ")
fmt.Println(bytes.Index(byteRespTrim, []byte("\x00")))
fmt.Print("total length = ")
fmt.Println(len(byteRespTrim))
byteRespTrim = bytes.Trim(byteRespTrim, "\x00")
fmt.Print("after trim found a null terminator at -- ")
loc := bytes.Index(byteRespTrim, []byte("\x00"))
fmt.Print(loc)
打电话时我得到以下信息
(master)⚡ % ./windows-dns-test create -d domain.com -n openshift-node-0 -t A -v 10.90.61.30
found a null terminator at -- 2102
total length = 2615
after trim found a null terminator at -- 2102
【问题讨论】:
标签: go