mirror of
				https://github.com/coredns/coredns.git
				synced 2025-11-03 18:53:13 -05:00 
			
		
		
		
	* plugin/dnstap: remove config struct this struct is an uneeded intermidiate to get a dnstap it can be removed. Remove the dnstapio subpkg: it's also not needed. Make *many* functions and structs private now that we can. Signed-off-by: Miek Gieben <miek@miek.nl> * correct logging Signed-off-by: Miek Gieben <miek@miek.nl>
		
			
				
	
	
		
			41 lines
		
	
	
		
			857 B
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			857 B
		
	
	
	
		
			Go
		
	
	
	
	
	
package dnstap
 | 
						|
 | 
						|
import (
 | 
						|
	"io"
 | 
						|
	"time"
 | 
						|
 | 
						|
	tap "github.com/dnstap/golang-dnstap"
 | 
						|
	fs "github.com/farsightsec/golang-framestream"
 | 
						|
	"github.com/golang/protobuf/proto"
 | 
						|
)
 | 
						|
 | 
						|
// encoder wraps a golang-framestream.Encoder.
 | 
						|
type encoder struct {
 | 
						|
	fs *fs.Encoder
 | 
						|
}
 | 
						|
 | 
						|
func newEncoder(w io.Writer, timeout time.Duration) (*encoder, error) {
 | 
						|
	fs, err := fs.NewEncoder(w, &fs.EncoderOptions{
 | 
						|
		ContentType:   []byte("protobuf:dnstap.Dnstap"),
 | 
						|
		Bidirectional: true,
 | 
						|
		Timeout:       timeout,
 | 
						|
	})
 | 
						|
	if err != nil {
 | 
						|
		return nil, err
 | 
						|
	}
 | 
						|
	return &encoder{fs}, nil
 | 
						|
}
 | 
						|
 | 
						|
func (e *encoder) writeMsg(msg *tap.Dnstap) error {
 | 
						|
	buf, err := proto.Marshal(msg)
 | 
						|
	if err != nil {
 | 
						|
		return err
 | 
						|
	}
 | 
						|
 | 
						|
	_, err = e.fs.Write(buf) // n < len(buf) should return an error?
 | 
						|
	return err
 | 
						|
}
 | 
						|
 | 
						|
func (e *encoder) flush() error { return e.fs.Flush() }
 | 
						|
func (e *encoder) close() error { return e.fs.Close() }
 |