diff --git a/core/discov/config.go b/core/discov/config.go index c1f6b7b1..1557b4f8 100644 --- a/core/discov/config.go +++ b/core/discov/config.go @@ -2,6 +2,13 @@ package discov import "errors" +var ( + // errEmptyEtcdHosts indicates that etcd hosts are empty. + errEmptyEtcdHosts = errors.New("empty etcd hosts") + // errEmptyEtcdKey indicates that etcd key is empty. + errEmptyEtcdKey = errors.New("empty etcd key") +) + // EtcdConf is the config item with the given key on etcd. type EtcdConf struct { Hosts []string @@ -27,9 +34,9 @@ func (c EtcdConf) HasTLS() bool { // Validate validates c. func (c EtcdConf) Validate() error { if len(c.Hosts) == 0 { - return errors.New("empty etcd hosts") + return errEmptyEtcdHosts } else if len(c.Key) == 0 { - return errors.New("empty etcd key") + return errEmptyEtcdKey } else { return nil } diff --git a/core/filex/rangereader.go b/core/filex/rangereader.go index cd69f678..0a962e51 100644 --- a/core/filex/rangereader.go +++ b/core/filex/rangereader.go @@ -5,6 +5,9 @@ import ( "os" ) +// errExceedFileSize indicates that the file size is exceeded. +var errExceedFileSize = errors.New("exceed file size") + // A RangeReader is used to read a range of content from a file. type RangeReader struct { file *os.File @@ -29,7 +32,7 @@ func (rr *RangeReader) Read(p []byte) (n int, err error) { } if rr.stop < rr.start || rr.start >= stat.Size() { - return 0, errors.New("exceed file size") + return 0, errExceedFileSize } if rr.stop-rr.start < int64(len(p)) { diff --git a/core/jsonx/json.go b/core/jsonx/json.go index c4f60b68..176e30a0 100644 --- a/core/jsonx/json.go +++ b/core/jsonx/json.go @@ -51,5 +51,5 @@ func unmarshalUseNumber(decoder *json.Decoder, v interface{}) error { } func formatError(v string, err error) error { - return fmt.Errorf("string: `%s`, error: `%s`", v, err.Error()) + return fmt.Errorf("string: `%s`, error: `%w`", v, err) } diff --git a/core/timex/ticker.go b/core/timex/ticker.go index 59b5eb9d..2691a030 100644 --- a/core/timex/ticker.go +++ b/core/timex/ticker.go @@ -7,6 +7,9 @@ import ( "github.com/zeromicro/go-zero/core/lang" ) +// errTimeout indicates a timeout. +var errTimeout = errors.New("timeout") + type ( // Ticker interface wraps the Chan and Stop methods. Ticker interface { @@ -70,7 +73,7 @@ func (ft *fakeTicker) Tick() { func (ft *fakeTicker) Wait(d time.Duration) error { select { case <-time.After(d): - return errors.New("timeout") + return errTimeout case <-ft.done: return nil }