Skip to content

Commit 48da7da

Browse files
committed
removed 'self' from the functions
1 parent 7c5913a commit 48da7da

File tree

3 files changed

+56
-56
lines changed

3 files changed

+56
-56
lines changed

handler.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ func NewChannelHandler(channel LogPartsChannel) *ChannelHandler {
2525
}
2626

2727
//The channel to be used
28-
func (self *ChannelHandler) SetChannel(channel LogPartsChannel) {
29-
self.channel = channel
28+
func (h *ChannelHandler) SetChannel(channel LogPartsChannel) {
29+
h.channel = channel
3030
}
3131

3232
//Syslog entry receiver
33-
func (self *ChannelHandler) Handle(logParts syslogparser.LogParts, messageLength int64, err error) {
34-
self.channel <- logParts
33+
func (h *ChannelHandler) Handle(logParts syslogparser.LogParts, messageLength int64, err error) {
34+
h.channel <- logParts
3535
}

server.go

+48-48
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,22 @@ func NewServer() *Server {
3333
}
3434

3535
//Sets the syslog format (RFC3164 or RFC5424 or RFC6587)
36-
func (self *Server) SetFormat(f format.Format) {
37-
self.format = f
36+
func (s *Server) SetFormat(f format.Format) {
37+
s.format = f
3838
}
3939

4040
//Sets the handler, this handler with receive every syslog entry
41-
func (self *Server) SetHandler(handler Handler) {
42-
self.handler = handler
41+
func (s *Server) SetHandler(handler Handler) {
42+
s.handler = handler
4343
}
4444

4545
//Sets the connection timeout for TCP connections, in milliseconds
46-
func (self *Server) SetTimeout(millseconds int64) {
47-
self.readTimeoutMilliseconds = millseconds
46+
func (s *Server) SetTimeout(millseconds int64) {
47+
s.readTimeoutMilliseconds = millseconds
4848
}
4949

5050
//Configure the server for listen on an UDP addr
51-
func (self *Server) ListenUDP(addr string) error {
51+
func (s *Server) ListenUDP(addr string) error {
5252
udpAddr, err := net.ResolveUDPAddr("udp", addr)
5353
if err != nil {
5454
return err
@@ -59,12 +59,12 @@ func (self *Server) ListenUDP(addr string) error {
5959
return err
6060
}
6161

62-
self.connections = append(self.connections, connection)
62+
s.connections = append(s.connections, connection)
6363
return nil
6464
}
6565

6666
//Configure the server for listen on an unix socket
67-
func (self *Server) ListenUnixgram(addr string) error {
67+
func (s *Server) ListenUnixgram(addr string) error {
6868
unixAddr, err := net.ResolveUnixAddr("unixgram", addr)
6969
if err != nil {
7070
return err
@@ -75,12 +75,12 @@ func (self *Server) ListenUnixgram(addr string) error {
7575
return err
7676
}
7777

78-
self.connections = append(self.connections, connection)
78+
s.connections = append(s.connections, connection)
7979
return nil
8080
}
8181

8282
//Configure the server for listen on a TCP addr
83-
func (self *Server) ListenTCP(addr string) error {
83+
func (s *Server) ListenTCP(addr string) error {
8484
tcpAddr, err := net.ResolveTCPAddr("tcp", addr)
8585
if err != nil {
8686
return err
@@ -91,39 +91,39 @@ func (self *Server) ListenTCP(addr string) error {
9191
return err
9292
}
9393

94-
self.doneTcp = make(chan bool)
95-
self.listeners = append(self.listeners, listener)
94+
s.doneTcp = make(chan bool)
95+
s.listeners = append(s.listeners, listener)
9696
return nil
9797
}
9898

9999
//Starts the server, all the go routines goes to live
100-
func (self *Server) Boot() error {
101-
if self.format == nil {
100+
func (s *Server) Boot() error {
101+
if s.format == nil {
102102
return errors.New("please set a valid format")
103103
}
104104

105-
if self.handler == nil {
105+
if s.handler == nil {
106106
return errors.New("please set a valid handler")
107107
}
108108

109-
for _, listener := range self.listeners {
110-
self.goAcceptConnection(listener)
109+
for _, listener := range s.listeners {
110+
s.goAcceptConnection(listener)
111111
}
112112

113-
for _, connection := range self.connections {
114-
self.goScanConnection(connection, false)
113+
for _, connection := range s.connections {
114+
s.goScanConnection(connection, false)
115115
}
116116

117117
return nil
118118
}
119119

120-
func (self *Server) goAcceptConnection(listener *net.TCPListener) {
121-
self.wait.Add(1)
120+
func (s *Server) goAcceptConnection(listener *net.TCPListener) {
121+
s.wait.Add(1)
122122
go func(listener *net.TCPListener) {
123123
loop:
124124
for {
125125
select {
126-
case <-self.doneTcp:
126+
case <-s.doneTcp:
127127
break loop
128128
default:
129129
}
@@ -132,16 +132,16 @@ func (self *Server) goAcceptConnection(listener *net.TCPListener) {
132132
continue
133133
}
134134

135-
self.goScanConnection(connection, true)
135+
s.goScanConnection(connection, true)
136136
}
137137

138-
self.wait.Done()
138+
s.wait.Done()
139139
}(listener)
140140
}
141141

142-
func (self *Server) goScanConnection(connection net.Conn, needClose bool) {
142+
func (s *Server) goScanConnection(connection net.Conn, needClose bool) {
143143
scanner := bufio.NewScanner(connection)
144-
if sf := self.format.GetSplitFunc(); sf != nil {
144+
if sf := s.format.GetSplitFunc(); sf != nil {
145145
scanner.Split(sf)
146146
}
147147

@@ -152,79 +152,79 @@ func (self *Server) goScanConnection(connection net.Conn, needClose bool) {
152152
scanCloser = &ScanCloser{scanner, nil}
153153
}
154154

155-
self.wait.Add(1)
156-
go self.scan(scanCloser)
155+
s.wait.Add(1)
156+
go s.scan(scanCloser)
157157
}
158158

159-
func (self *Server) scan(scanCloser *ScanCloser) {
159+
func (s *Server) scan(scanCloser *ScanCloser) {
160160
if scanCloser.closer == nil {
161161
// UDP
162162
for scanCloser.Scan() {
163-
self.parser([]byte(scanCloser.Text()))
163+
s.parser([]byte(scanCloser.Text()))
164164
}
165165
} else {
166166
// TCP
167167
loop:
168168
for {
169169
select {
170-
case <-self.doneTcp:
170+
case <-s.doneTcp:
171171
break loop
172172
default:
173173
}
174-
if self.readTimeoutMilliseconds > 0 {
175-
scanCloser.closer.SetReadDeadline(time.Now().Add(time.Duration(self.readTimeoutMilliseconds) * time.Millisecond))
174+
if s.readTimeoutMilliseconds > 0 {
175+
scanCloser.closer.SetReadDeadline(time.Now().Add(time.Duration(s.readTimeoutMilliseconds) * time.Millisecond))
176176
}
177177
if scanCloser.Scan() {
178-
self.parser([]byte(scanCloser.Text()))
178+
s.parser([]byte(scanCloser.Text()))
179179
} else {
180180
break loop
181181
}
182182
}
183183
scanCloser.closer.Close()
184184
}
185185

186-
self.wait.Done()
186+
s.wait.Done()
187187
}
188188

189-
func (self *Server) parser(line []byte) {
190-
parser := self.format.GetParser(line)
189+
func (s *Server) parser(line []byte) {
190+
parser := s.format.GetParser(line)
191191
err := parser.Parse()
192192
if err != nil {
193-
self.lastError = err
193+
s.lastError = err
194194
}
195195

196-
go self.handler.Handle(parser.Dump(), int64(len(line)), err)
196+
go s.handler.Handle(parser.Dump(), int64(len(line)), err)
197197
}
198198

199199
//Returns the last error
200-
func (self *Server) GetLastError() error {
201-
return self.lastError
200+
func (s *Server) GetLastError() error {
201+
return s.lastError
202202
}
203203

204204
//Kill the server
205-
func (self *Server) Kill() error {
206-
for _, connection := range self.connections {
205+
func (s *Server) Kill() error {
206+
for _, connection := range s.connections {
207207
err := connection.Close()
208208
if err != nil {
209209
return err
210210
}
211211
}
212212

213-
for _, listener := range self.listeners {
213+
for _, listener := range s.listeners {
214214
err := listener.Close()
215215
if err != nil {
216216
return err
217217
}
218218
}
219219
// Only need to close channel once to broadcast to all waiting
220-
close(self.doneTcp)
220+
close(s.doneTcp)
221221

222222
return nil
223223
}
224224

225225
//Waits until the server stops
226-
func (self *Server) Wait() {
227-
self.wait.Wait()
226+
func (s *Server) Wait() {
227+
s.wait.Wait()
228228
}
229229

230230
type TimeoutCloser interface {

server_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ type HandlerMock struct {
5353
LastError error
5454
}
5555

56-
func (self *HandlerMock) Handle(logParts syslogparser.LogParts, msgLen int64, err error) {
57-
self.LastLogParts = logParts
58-
self.LastMessageLength = msgLen
59-
self.LastError = err
56+
func (s *HandlerMock) Handle(logParts syslogparser.LogParts, msgLen int64, err error) {
57+
s.LastLogParts = logParts
58+
s.LastMessageLength = msgLen
59+
s.LastError = err
6060
}
6161

6262
type ConnMock struct {

0 commit comments

Comments
 (0)