Skip to content

Commit

Permalink
aliasing LogParts
Browse files Browse the repository at this point in the history
  • Loading branch information
mcuadros committed Apr 25, 2016
1 parent 280fd46 commit d3055b9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
8 changes: 5 additions & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"gopkg.in/mcuadros/go-syslog.v2/internal/syslogparser"
)

type LogParts syslogparser.LogParts

//The handler receive every syslog entry at Handle method
type Handler interface {
Handle(syslogparser.LogParts, int64, error)
Handle(LogParts, int64, error)
}

type LogPartsChannel chan syslogparser.LogParts
type LogPartsChannel chan LogParts

//The ChannelHandler will send all the syslog entries into the given channel
type ChannelHandler struct {
Expand All @@ -30,6 +32,6 @@ func (h *ChannelHandler) SetChannel(channel LogPartsChannel) {
}

//Syslog entry receiver
func (h *ChannelHandler) Handle(logParts syslogparser.LogParts, messageLength int64, err error) {
func (h *ChannelHandler) Handle(logParts LogParts, messageLength int64, err error) {
h.channel <- logParts
}
3 changes: 1 addition & 2 deletions handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package syslog

import (
. "gopkg.in/check.v1"
"gopkg.in/mcuadros/go-syslog.v2/internal/syslogparser"
)

type HandlerSuite struct{}

var _ = Suite(&HandlerSuite{})

func (s *HandlerSuite) TestHandle(c *C) {
logPart := syslogparser.LogParts{"tag": "foo"}
logPart := LogParts{"tag": "foo"}

channel := make(LogPartsChannel, 1)
handler := NewChannelHandler(channel)
Expand Down
2 changes: 1 addition & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (s *Server) parser(line []byte, client string, tlsPeer string) {
}
logParts["tls_peer"] = tlsPeer

s.handler.Handle(logParts, int64(len(line)), err)
s.handler.Handle(LogParts(logParts), int64(len(line)), err)
}

//Returns the last error
Expand Down
5 changes: 2 additions & 3 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"time"

. "gopkg.in/check.v1"
"gopkg.in/mcuadros/go-syslog.v2/internal/syslogparser"
)

func Test(t *testing.T) { TestingT(t) }
Expand Down Expand Up @@ -51,12 +50,12 @@ func (s *ServerSuite) TestTailFile(c *C) {
}

type HandlerMock struct {
LastLogParts syslogparser.LogParts
LastLogParts LogParts
LastMessageLength int64
LastError error
}

func (s *HandlerMock) Handle(logParts syslogparser.LogParts, msgLen int64, err error) {
func (s *HandlerMock) Handle(logParts LogParts, msgLen int64, err error) {
s.LastLogParts = logParts
s.LastMessageLength = msgLen
s.LastError = err
Expand Down

0 comments on commit d3055b9

Please sign in to comment.