/
message.go
55 lines (46 loc) · 955 Bytes
/
message.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package nspub
import (
"encoding/json"
"net"
"time"
"github.com/miekg/dns"
)
// Header is the simplified structure for deserialization.
type Header struct {
Name string
}
// Question is the simplified structure for deserialization.
type Question struct {
Name string
}
// Answer is the simplified structure for deserialization.
type Answer struct {
Hdr Header
A string
AAAA string
}
// Msg is the simplified structure for deserialization.
type Msg struct {
ID int
Question []Question
Answer []Answer
}
// Message is the simplified structure for deserialization.
type Message struct {
ClientIP string
Time time.Time
Msg Msg
}
// SerializeMessage is the structure serialized to send.
type SerializeMessage struct {
ClientIP net.IP
Time time.Time
Msg *dns.Msg
}
func (m *SerializeMessage) String() string {
data, err := json.Marshal(m)
if err != nil {
return err.Error()
}
return string(data)
}