refactoring: add common package

The common package defines the interfaces that a protocol must implement
and contain code that can be shared among supported protocols.

This way should be easier to support new protocols
This commit is contained in:
Nicola Murino
2020-07-24 23:39:38 +02:00
parent ded8fad5e4
commit 4e41a5583d
62 changed files with 4893 additions and 3140 deletions

View File

@@ -5,7 +5,6 @@ import (
"os"
"path/filepath"
"runtime"
"sync"
"github.com/rs/zerolog"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
@@ -38,9 +37,9 @@ func InitLogger(logFilePath string, logMaxSize, logMaxBackups, logMaxAge int, lo
})
EnableConsoleLogger(level)
} else {
logger = zerolog.New(logSyncWrapper{
logger = zerolog.New(&logSyncWrapper{
output: os.Stdout,
lock: new(sync.Mutex)})
})
consoleLogger = zerolog.Nop()
}
logger.Level(level)

View File

@@ -6,12 +6,12 @@ import (
)
type logSyncWrapper struct {
lock *sync.Mutex
sync.Mutex
output *os.File
}
func (l logSyncWrapper) Write(b []byte) (n int, err error) {
l.lock.Lock()
defer l.lock.Unlock()
func (l *logSyncWrapper) Write(b []byte) (n int, err error) {
l.Lock()
defer l.Unlock()
return l.output.Write(b)
}