hotime/common/error.go

30 lines
431 B
Go
Raw Normal View History

2021-05-24 07:27:41 +08:00
package common
2017-08-04 08:20:59 +00:00
2021-05-25 19:53:34 +08:00
import (
"github.com/sirupsen/logrus"
"sync"
2021-05-25 19:53:34 +08:00
)
// Error 框架层处理错误
2017-08-04 08:20:59 +00:00
type Error struct {
Logger *logrus.Logger
error
mu sync.RWMutex
2017-08-04 08:20:59 +00:00
}
func (that *Error) GetError() error {
that.mu.RLock()
defer that.mu.RUnlock()
return that.error
2017-08-04 08:20:59 +00:00
}
func (that *Error) SetError(err error) {
that.mu.Lock()
that.error = err
that.mu.Unlock()
2021-05-25 20:27:24 +08:00
if that.Logger != nil && err != nil {
2021-05-25 19:53:34 +08:00
that.Logger.Warn(err)
}
2017-08-04 08:20:59 +00:00
}