dns: marshal to io.writer instead of byte slice

This commit is contained in:
nadoo committed 2020-04-20 12:41:53 +08:00
1 parent a0542a028e
commit 149824cc20
5 files changed
+55 -67

No files matched your search

+3 -5
View File
@@ -1,6 +1,7 @@
package dns
import (
"bytes"
"encoding/binary"
"errors"
"io"
@@ -9,7 +10,6 @@ import (
"time"
"github.com/nadoo/glider/common/log"
"github.com/nadoo/glider/common/pool"
"github.com/nadoo/glider/proxy"
)
@@ -257,10 +257,8 @@ func (c *Client) AddRecord(record string) error {
b, _ := m.Marshal()
buf := pool.GetWriteBuffer()
defer pool.PutWriteBuffer(buf)
binary.Write(buf, binary.BigEndian, uint16(len(b)))
var buf bytes.Buffer
binary.Write(&buf, binary.BigEndian, uint16(len(b)))
buf.Write(b)
c.cache.Put(getKey(m.Question), buf.Bytes(), LongTTL)