fix sonar problem

* Delete FIXME comment, because `string == ""` is beter than `len(string)` for checking string existence(by sonar)
* Remove duplicated code
* Fill empty block of code
This commit is contained in:
t29kida 2021-06-08 23:06:19 +09:00
parent 18de06b970
commit 4eb19f938a
4 changed files with 5 additions and 34 deletions

View File

@ -73,3 +73,4 @@
- [4647](https://github.com/beego/beego/pull/4647) - [4647](https://github.com/beego/beego/pull/4647)
- [4648](https://github.com/beego/beego/pull/4648) - [4648](https://github.com/beego/beego/pull/4648)
- [4649](https://github.com/beego/beego/pull/4649) - [4649](https://github.com/beego/beego/pull/4649)
- [4660](https://github.com/beego/beego/pull/4660)

View File

@ -2760,6 +2760,7 @@ func TestStrPkInsert(t *testing.T) {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
if err.Error() == "postgres version must 9.5 or higher" || err.Error() == "`sqlite3` nonsupport InsertOrUpdate in beego" { if err.Error() == "postgres version must 9.5 or higher" || err.Error() == "`sqlite3` nonsupport InsertOrUpdate in beego" {
return
} else if err == ErrLastInsertIdUnavailable { } else if err == ErrLastInsertIdUnavailable {
return return
} else { } else {

View File

@ -210,7 +210,6 @@ func (c *JSONConfigContainer) String(key string) (string, error) {
// DefaultString returns the string value for a given key. // DefaultString returns the string value for a given key.
// if err != nil return defaultval // if err != nil return defaultval
func (c *JSONConfigContainer) DefaultString(key string, defaultVal string) string { func (c *JSONConfigContainer) DefaultString(key string, defaultVal string) string {
// TODO FIXME should not use "" to replace non existence
if v, err := c.String(key); v != "" && err == nil { if v, err := c.String(key); v != "" && err == nil {
return v return v
} }

View File

@ -520,49 +520,19 @@ func (bl *BeeLogger) Debug(format string, v ...interface{}) {
// Warn Log WARN level message. // Warn Log WARN level message.
// compatibility alias for Warning() // compatibility alias for Warning()
func (bl *BeeLogger) Warn(format string, v ...interface{}) { func (bl *BeeLogger) Warn(format string, v ...interface{}) {
if LevelWarn > bl.level { bl.Warning(format, v...)
return
}
lm := &LogMsg{
Level: LevelWarn,
Msg: format,
When: time.Now(),
Args: v,
}
bl.writeMsg(lm)
} }
// Info Log INFO level message. // Info Log INFO level message.
// compatibility alias for Informational() // compatibility alias for Informational()
func (bl *BeeLogger) Info(format string, v ...interface{}) { func (bl *BeeLogger) Info(format string, v ...interface{}) {
if LevelInfo > bl.level { bl.Informational(format, v...)
return
}
lm := &LogMsg{
Level: LevelInfo,
Msg: format,
When: time.Now(),
Args: v,
}
bl.writeMsg(lm)
} }
// Trace Log TRACE level message. // Trace Log TRACE level message.
// compatibility alias for Debug() // compatibility alias for Debug()
func (bl *BeeLogger) Trace(format string, v ...interface{}) { func (bl *BeeLogger) Trace(format string, v ...interface{}) {
if LevelDebug > bl.level { bl.Debug(format, v...)
return
}
lm := &LogMsg{
Level: LevelDebug,
Msg: format,
When: time.Now(),
Args: v,
}
bl.writeMsg(lm)
} }
// Flush flush all chan data. // Flush flush all chan data.