Make the linter happy

Signed-off-by: David Gageot <david.gageot@docker.com>
This commit is contained in:
David Gageot 2022-07-22 15:02:19 +02:00
parent 0b136bf80d
commit acbef4424a
No known key found for this signature in database
GPG Key ID: 93C3F22BE5D3A40B
3 changed files with 23 additions and 23 deletions

View File

@ -15,13 +15,13 @@ const (
logDumpFollow logDumpFollow
) )
type LogEntry struct { type logEntry struct {
Time time.Time `json:"time"` Time time.Time `json:"time"`
Source string `json:"source"` Source string `json:"source"`
Msg string `json:"msg"` Msg string `json:"msg"`
} }
func (msg *LogEntry) String() string { func (msg *logEntry) String() string {
return fmt.Sprintf("%s;%s;%s", msg.Time.Format(time.RFC3339Nano), strings.ReplaceAll(msg.Source, `;`, `\;`), msg.Msg) return fmt.Sprintf("%s;%s;%s", msg.Time.Format(time.RFC3339Nano), strings.ReplaceAll(msg.Source, `;`, `\;`), msg.Msg)
} }
@ -61,7 +61,7 @@ func main() {
panic(err) panic(err)
} }
var entry LogEntry var entry logEntry
decoder := json.NewDecoder(conn) decoder := json.NewDecoder(conn)
for { for {
if err := decoder.Decode(&entry); err != nil { if err := decoder.Decode(&entry); err != nil {

View File

@ -17,13 +17,13 @@ import (
"time" "time"
) )
type LogEntry struct { type logEntry struct {
Time time.Time `json:"time"` Time time.Time `json:"time"`
Source string `json:"source"` Source string `json:"source"`
Msg string `json:"msg"` Msg string `json:"msg"`
} }
func (msg *LogEntry) String() string { func (msg *logEntry) String() string {
return fmt.Sprintf("%s;%s;%s", msg.Time.Format(time.RFC3339Nano), strings.ReplaceAll(msg.Source, `;`, `\;`), msg.Msg) return fmt.Sprintf("%s;%s;%s", msg.Time.Format(time.RFC3339Nano), strings.ReplaceAll(msg.Source, `;`, `\;`), msg.Msg)
} }
@ -47,13 +47,13 @@ type queryMessage struct {
type connListener struct { type connListener struct {
conn net.Conn conn net.Conn
output chan *LogEntry output chan *logEntry
err error err error
exitOnEOF bool // exit instead of blocking if no more data in read buffer exitOnEOF bool // exit instead of blocking if no more data in read buffer
} }
func doLog(logCh chan LogEntry, msg string) { func doLog(logCh chan logEntry, msg string) {
logCh <- LogEntry{ logCh <- logEntry{
Time: time.Now(), Time: time.Now(),
Source: "memlogd", Source: "memlogd",
Msg: msg, Msg: msg,
@ -72,7 +72,7 @@ func logQueryHandler(l *connListener) {
} }
} }
func ringBufferHandler(ringSize, chanSize int, logCh chan LogEntry, queryMsgChan chan queryMessage) { func ringBufferHandler(ringSize, chanSize int, logCh chan logEntry, queryMsgChan chan queryMessage) {
// Anything that interacts with the ring buffer goes through this handler // Anything that interacts with the ring buffer goes through this handler
ring := ring.New(ringSize) ring := ring.New(ringSize)
listeners := list.New() listeners := list.New()
@ -112,7 +112,7 @@ func ringBufferHandler(ringSize, chanSize int, logCh chan LogEntry, queryMsgChan
case msg := <-queryMsgChan: case msg := <-queryMsgChan:
l := connListener{ l := connListener{
conn: msg.conn, conn: msg.conn,
output: make(chan *LogEntry, chanSize), output: make(chan *logEntry, chanSize),
err: nil, err: nil,
exitOnEOF: (msg.mode == logDump), exitOnEOF: (msg.mode == logDump),
} }
@ -124,7 +124,7 @@ func ringBufferHandler(ringSize, chanSize int, logCh chan LogEntry, queryMsgChan
if msg.mode == logDumpFollow || msg.mode == logDump { if msg.mode == logDumpFollow || msg.mode == logDump {
// fill with current data in buffer // fill with current data in buffer
ring.Do(func(f interface{}) { ring.Do(func(f interface{}) {
if msg, ok := f.(LogEntry); ok { if msg, ok := f.(logEntry); ok {
select { select {
case l.output <- &msg: case l.output <- &msg:
default: default:
@ -140,7 +140,7 @@ func ringBufferHandler(ringSize, chanSize int, logCh chan LogEntry, queryMsgChan
} }
} }
func receiveQueryHandler(l *net.UnixListener, logCh chan LogEntry, queryMsgChan chan queryMessage) { func receiveQueryHandler(l *net.UnixListener, logCh chan logEntry, queryMsgChan chan queryMessage) {
for { for {
var conn *net.UnixConn var conn *net.UnixConn
var err error var err error
@ -157,7 +157,7 @@ func receiveQueryHandler(l *net.UnixListener, logCh chan LogEntry, queryMsgChan
} }
} }
func receiveFdHandler(conn *net.UnixConn, logCh chan LogEntry, fdMsgChan chan fdMessage) { func receiveFdHandler(conn *net.UnixConn, logCh chan logEntry, fdMsgChan chan fdMessage) {
oob := make([]byte, 512) oob := make([]byte, 512)
b := make([]byte, 512) b := make([]byte, 512)
@ -195,7 +195,7 @@ func receiveFdHandler(conn *net.UnixConn, logCh chan LogEntry, fdMsgChan chan fd
} }
} }
func readLogFromFd(maxLineLen int, fd int, source string, logCh chan LogEntry) { func readLogFromFd(maxLineLen int, fd int, source string, logCh chan logEntry) {
f := os.NewFile(uintptr(fd), "") f := os.NewFile(uintptr(fd), "")
defer f.Close() defer f.Close()
@ -217,7 +217,7 @@ func readLogFromFd(maxLineLen int, fd int, source string, logCh chan LogEntry) {
if buffer.Len() > maxLineLen { if buffer.Len() > maxLineLen {
buffer.Truncate(maxLineLen) buffer.Truncate(maxLineLen)
} }
logCh <- LogEntry{ logCh <- logEntry{
Time: time.Now(), Time: time.Now(),
Source: source, Source: source,
Msg: buffer.String(), Msg: buffer.String(),
@ -228,7 +228,7 @@ func readLogFromFd(maxLineLen int, fd int, source string, logCh chan LogEntry) {
} }
} }
func loggingRequestHandler(lineMaxLength int, logCh chan LogEntry, fdMsgChan chan fdMessage) { func loggingRequestHandler(lineMaxLength int, logCh chan logEntry, fdMsgChan chan fdMessage) {
for msg := range fdMsgChan { for msg := range fdMsgChan {
go readLogFromFd(lineMaxLength, msg.fd, msg.name, logCh) go readLogFromFd(lineMaxLength, msg.fd, msg.name, logCh)
} }
@ -314,7 +314,7 @@ func main() {
os.Exit(0) os.Exit(0)
} }
logCh := make(chan LogEntry) logCh := make(chan logEntry)
fdMsgChan := make(chan fdMessage) fdMsgChan := make(chan fdMessage)
queryMsgChan := make(chan queryMessage) queryMsgChan := make(chan queryMessage)

View File

@ -15,7 +15,7 @@ func TestNonblock(t *testing.T) {
// Test that writes to the logger don't block because it is full // Test that writes to the logger don't block because it is full
linesInBuffer := 10 linesInBuffer := 10
logCh := make(chan LogEntry) logCh := make(chan logEntry)
queryMsgChan := make(chan queryMessage) queryMsgChan := make(chan queryMessage)
go ringBufferHandler(linesInBuffer, linesInBuffer, logCh, queryMsgChan) go ringBufferHandler(linesInBuffer, linesInBuffer, logCh, queryMsgChan)
@ -23,7 +23,7 @@ func TestNonblock(t *testing.T) {
// Overflow the log to make sure it doesn't block // Overflow the log to make sure it doesn't block
for i := 0; i < 2*linesInBuffer; i++ { for i := 0; i < 2*linesInBuffer; i++ {
select { select {
case logCh <- LogEntry{Time: time.Now(), Source: "memlogd", Msg: "hello TestNonblock"}: case logCh <- logEntry{Time: time.Now(), Source: "memlogd", Msg: "hello TestNonblock"}:
continue continue
case <-time.After(time.Second): case <-time.After(time.Second):
t.Errorf("write to the logger blocked for over 1s after %d (size was set to %d)", i, linesInBuffer) t.Errorf("write to the logger blocked for over 1s after %d (size was set to %d)", i, linesInBuffer)
@ -35,14 +35,14 @@ func TestFinite(t *testing.T) {
// Test that the logger doesn't store more than its configured maximum size // Test that the logger doesn't store more than its configured maximum size
linesInBuffer := 10 linesInBuffer := 10
logCh := make(chan LogEntry) logCh := make(chan logEntry)
queryMsgChan := make(chan queryMessage) queryMsgChan := make(chan queryMessage)
go ringBufferHandler(linesInBuffer, linesInBuffer, logCh, queryMsgChan) go ringBufferHandler(linesInBuffer, linesInBuffer, logCh, queryMsgChan)
// Overflow the log by 2x // Overflow the log by 2x
for i := 0; i < 2*linesInBuffer; i++ { for i := 0; i < 2*linesInBuffer; i++ {
logCh <- LogEntry{Time: time.Now(), Source: "memlogd", Msg: "hello TestFinite"} logCh <- logEntry{Time: time.Now(), Source: "memlogd", Msg: "hello TestFinite"}
} }
a, b := loopback() a, b := loopback()
defer a.Close() defer a.Close()
@ -75,14 +75,14 @@ func TestFinite2(t *testing.T) {
linesInBuffer := 10 linesInBuffer := 10
// the output buffer size will be 1/2 of the ring // the output buffer size will be 1/2 of the ring
outputBufferSize := linesInBuffer / 2 outputBufferSize := linesInBuffer / 2
logCh := make(chan LogEntry) logCh := make(chan logEntry)
queryMsgChan := make(chan queryMessage) queryMsgChan := make(chan queryMessage)
go ringBufferHandler(linesInBuffer, outputBufferSize, logCh, queryMsgChan) go ringBufferHandler(linesInBuffer, outputBufferSize, logCh, queryMsgChan)
// fill the ring // fill the ring
for i := 0; i < linesInBuffer; i++ { for i := 0; i < linesInBuffer; i++ {
logCh <- LogEntry{Time: time.Now(), Source: "memlogd", Msg: "hello TestFinite2"} logCh <- logEntry{Time: time.Now(), Source: "memlogd", Msg: "hello TestFinite2"}
} }
a, b := loopback() a, b := loopback()