Fix lint and format code in core dir

This commit is contained in:
loyalsoldier
2021-06-06 21:00:27 +08:00
parent ca328208cc
commit 41790b80ac
42 changed files with 75 additions and 109 deletions

View File

@@ -180,7 +180,6 @@ func (c *aliLSWriter) WriteMsg(lm *logs.LogMsg) error {
// Flush implementing method. empty.
func (c *aliLSWriter) Flush() {
// flush all group
for _, lg := range c.group {
c.flush(lg)
@@ -192,7 +191,6 @@ func (c *aliLSWriter) Destroy() {
}
func (c *aliLSWriter) flush(lg *LogGroup) {
c.lock.Lock()
defer c.lock.Unlock()
err := c.store.PutLogs(lg)

View File

@@ -128,7 +128,6 @@ func (p *LogProject) GetLogStore(name string) (s *LogStore, err error) {
// and ttl is time-to-live(in day) of logs,
// and shardCnt is the number of shards.
func (p *LogProject) CreateLogStore(name string, ttl, shardCnt int) (err error) {
type Body struct {
Name string `json:"logstoreName"`
TTL int `json:"ttl"`
@@ -212,7 +211,6 @@ func (p *LogProject) DeleteLogStore(name string) (err error) {
// UpdateLogStore updates a logstore according by logstore name,
// obviously we can't modify the logstore name itself.
func (p *LogProject) UpdateLogStore(name string, ttl, shardCnt int) (err error) {
type Body struct {
Name string `json:"logstoreName"`
TTL int `json:"ttl"`
@@ -355,7 +353,6 @@ func (p *LogProject) GetMachineGroup(name string) (m *MachineGroup, err error) {
// CreateMachineGroup creates a new machine group in SLS.
func (p *LogProject) CreateMachineGroup(m *MachineGroup) (err error) {
body, err := json.Marshal(m)
if err != nil {
return
@@ -395,7 +392,6 @@ func (p *LogProject) CreateMachineGroup(m *MachineGroup) (err error) {
// UpdateMachineGroup updates a machine group.
func (p *LogProject) UpdateMachineGroup(m *MachineGroup) (err error) {
body, err := json.Marshal(m)
if err != nil {
return
@@ -555,7 +551,6 @@ func (p *LogProject) GetConfig(name string) (c *LogConfig, err error) {
// UpdateConfig updates a config.
func (p *LogProject) UpdateConfig(c *LogConfig) (err error) {
body, err := json.Marshal(c)
if err != nil {
return
@@ -595,7 +590,6 @@ func (p *LogProject) UpdateConfig(c *LogConfig) (err error) {
// CreateConfig creates a new config in SLS.
func (p *LogProject) CreateConfig(c *LogConfig) (err error) {
body, err := json.Marshal(c)
if err != nil {
return

View File

@@ -241,7 +241,6 @@ func (s *LogStore) GetLogsBytes(shardID int, cursor string,
// LogsBytesDecode decodes logs binary data retruned by GetLogsBytes API
func LogsBytesDecode(data []byte) (gl *LogGroupList, err error) {
gl = &LogGroupList{}
err = proto.Unmarshal(data, gl)
if err != nil {

View File

@@ -95,7 +95,6 @@ func (c *connWriter) WriteMsg(lm *LogMsg) error {
// Flush implementing method. empty.
func (c *connWriter) Flush() {
}
// Destroy destroy connection writer and close tcp listener.

View File

@@ -26,7 +26,6 @@ import (
// ConnTCPListener takes a TCP listener and accepts n TCP connections
// Returns connections using connChan
func connTCPListener(t *testing.T, n int, ln net.Listener, connChan chan<- net.Conn) {
// Listen and accept n incoming connections
for i := 0; i < n; i++ {
conn, err := ln.Accept()

View File

@@ -88,7 +88,6 @@ func newConsole() *consoleWriter {
// Init initianlizes the console logger.
// jsonConfig must be in the format '{"level":LevelTrace}'
func (c *consoleWriter) Init(config string) error {
if len(config) == 0 {
return nil
}
@@ -116,12 +115,10 @@ func (c *consoleWriter) WriteMsg(lm *LogMsg) error {
// Destroy implementing method. empty.
func (c *consoleWriter) Destroy() {
}
// Flush implementing method. empty.
func (c *consoleWriter) Flush() {
}
func init() {

View File

@@ -41,7 +41,6 @@ type esLogger struct {
}
func (el *esLogger) Format(lm *logs.LogMsg) string {
msg := lm.OldStyleFormat()
idx := LogDocument{
Timestamp: lm.When.Format(time.RFC3339),
@@ -60,7 +59,6 @@ func (el *esLogger) SetFormatter(f logs.LogFormatter) {
// {"dsn":"http://localhost:9200/","level":1}
func (el *esLogger) Init(config string) error {
err := json.Unmarshal([]byte(config), el)
if err != nil {
return err
@@ -113,7 +111,6 @@ func (el *esLogger) Destroy() {
// Flush is a empty method
func (el *esLogger) Flush() {
}
type LogDocument struct {

View File

@@ -117,7 +117,6 @@ func (w *fileLogWriter) SetFormatter(f LogFormatter) {
// "perm":"0600"
// }
func (w *fileLogWriter) Init(config string) error {
err := json.Unmarshal([]byte(config), w)
if err != nil {
return err
@@ -165,7 +164,6 @@ func (w *fileLogWriter) needRotateHourly(hour int) bool {
return (w.MaxLines > 0 && w.maxLinesCurLines >= w.MaxLines) ||
(w.MaxSize > 0 && w.maxSizeCurSize >= w.MaxSize) ||
(w.Hourly && hour != w.hourlyOpenDate)
}
// WriteMsg writes logger message into file.

View File

@@ -42,7 +42,7 @@ func TestFilePerm(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if file.Mode() != 0666 {
if file.Mode() != 0o666 {
t.Fatal("unexpected log file permission")
}
os.Remove("test.log")
@@ -74,7 +74,7 @@ func TestFile1(t *testing.T) {
lineNum++
}
}
var expected = LevelDebug + 1
expected := LevelDebug + 1
if lineNum != expected {
t.Fatal(lineNum, "not "+strconv.Itoa(expected)+" lines")
}
@@ -107,7 +107,7 @@ func TestFile2(t *testing.T) {
lineNum++
}
}
var expected = LevelError + 1
expected := LevelError + 1
if lineNum != expected {
t.Fatal(lineNum, "not "+strconv.Itoa(expected)+" lines")
}
@@ -164,6 +164,7 @@ func TestFileDailyRotate_05(t *testing.T) {
testFileDailyRotate(t, fn1, fn2)
os.Remove(fn)
}
func TestFileDailyRotate_06(t *testing.T) { // test file mode
log := NewLogger(10000)
log.SetLogger("file", `{"filename":"test3.log","maxlines":4}`)
@@ -177,7 +178,7 @@ func TestFileDailyRotate_06(t *testing.T) { // test file mode
log.Emergency("emergency")
rotateName := "test3" + fmt.Sprintf(".%s.%03d", time.Now().Format("2006-01-02"), 1) + ".log"
s, _ := os.Lstat(rotateName)
if s.Mode() != 0440 {
if s.Mode() != 0o440 {
os.Remove(rotateName)
os.Remove("test3.log")
t.Fatal("rotate file mode error")
@@ -250,7 +251,7 @@ func TestFileHourlyRotate_06(t *testing.T) { // test file mode
log.Emergency("emergency")
rotateName := "test3" + fmt.Sprintf(".%s.%03d", time.Now().Format("2006010215"), 1) + ".log"
s, _ := os.Lstat(rotateName)
if s.Mode() != 0440 {
if s.Mode() != 0o440 {
os.Remove(rotateName)
os.Remove("test3.log")
t.Fatal("rotate file mode error")
@@ -369,6 +370,7 @@ func testFileHourlyRotate(t *testing.T, fn1, fn2 string) {
}
fw.Destroy()
}
func exists(path string) (bool, error) {
_, err := os.Stat(path)
if err == nil {

View File

@@ -31,7 +31,6 @@ func newJLWriter() Logger {
// Init JLWriter with json config string
func (s *JLWriter) Init(config string) error {
res := json.Unmarshal([]byte(config), s)
if res == nil && len(s.Formatter) > 0 {
fmtr, ok := GetFormatter(s.Formatter)

View File

@@ -92,8 +92,10 @@ type Logger interface {
SetFormatter(f LogFormatter)
}
var adapters = make(map[string]newLoggerFunc)
var levelPrefix = [LevelDebug + 1]string{"[M]", "[A]", "[C]", "[E]", "[W]", "[N]", "[I]", "[D]"}
var (
adapters = make(map[string]newLoggerFunc)
levelPrefix = [LevelDebug + 1]string{"[M]", "[A]", "[C]", "[E]", "[W]", "[N]", "[I]", "[D]"}
)
// Register makes a log provide available by the provided name.
// If Register is called twice with the same name or if driver is nil,
@@ -201,7 +203,6 @@ func (bl *BeeLogger) setLogger(adapterName string, configs ...string) error {
}
err := lg.Init(config)
if err != nil {
fmt.Fprintln(os.Stderr, "logs.BeeLogger.SetLogger: "+err.Error())
return err

View File

@@ -112,8 +112,10 @@ var (
reset = string([]byte{27, 91, 48, 109})
)
var once sync.Once
var colorMap map[string]string
var (
once sync.Once
colorMap map[string]string
)
func initColor() {
if runtime.GOOS == "windows" {

View File

@@ -45,7 +45,6 @@ var levelNames = [...]string{"emergency", "alert", "critical", "error", "warning
// }
func (f *multiFileLogWriter) Init(config string) error {
writer := newFileWriter().(*fileLogWriter)
err := writer.Init(config)
if err != nil {

View File

@@ -60,7 +60,7 @@ func TestFiles_1(t *testing.T) {
lineNum++
}
}
var expected = 1
expected := 1
if fn == "" {
expected = LevelDebug + 1
}
@@ -74,5 +74,4 @@ func TestFiles_1(t *testing.T) {
}
os.Remove(file)
}
}