给出了我写的2个结构。
type DNSPacket struct {
header DNSHeader.DNSHeader
questions []DNSQuestion.DNSQuestion
answers []DNSRecord.DNSRecord
authorities []DNSRecord.DNSRecord
resources []DNSRecord.DNSRecord
}
type DNSHeader struct {
id uint16 //16bits
recursion_desired bool // 1 bit
truncated_message bool // 1 bit
authoritative_answer bool // 1 bit
opcode uint8 // 4 bits
response bool // 1 bit
rescode ResultCode // 4 bits
checking_disabled bool // 1 bit
authed_data bool // 1 bit
z bool // 1 bit
recursion_available bool // 1 bit
questions uint16 // 16 bits
answers uint16 // 16 bits
authoritative_entries uint16 // 16 bits
resource_entries uint16 // 16 bits
} // total 96 bits
现在,当我调用results.header.questions
时,结果是类型为DNSPacket变量,我将收到[go] result.header.questions undefined (cannot refer to unexported field or method questions)
错误。
我在做什么错?有解决方法吗?
谢谢。
答案 0 :(得分:3)
这里有一些问题:
dnsheader
,而不是DNSHeader
。在exported names上阅读规格,在package names上阅读“有效”