Address staticcheck issues

Fix `staticcheck` issues:
- S1028 use `fmt.Errorf` to construct formatted errors
- ST1017 yoda conditions
- ST1005 error message capitalization
- ST1006 avoid `self` as receiver name
- S1030 use `buf.String`
- S1011 avoid redundant loop when `append` suffices
- SA4006 unused value
- S1019 remove redundant capacity on `make` call
- SA2002 `t.Fatal` called outside of test

Exported error violates ST1012, which is ignored by this PR since rename may cause breaking changes.

Remove redundant parentheses wrapping, and use CamelCase naming while at it.
This commit is contained in:
Masih H. Derkani
2021-07-19 16:47:21 +01:00
parent 6f65c2c3af
commit 597b8983b0
20 changed files with 196 additions and 212 deletions

View File

@@ -45,35 +45,35 @@ func NewFuture() *Future {
}
// Get blocks until the Future has a value set.
func (self *Future) Get() (interface{}, error) {
self.mutex.Lock()
defer self.mutex.Unlock()
func (f *Future) Get() (interface{}, error) {
f.mutex.Lock()
defer f.mutex.Unlock()
for {
if self.received {
return self.val, self.err
if f.received {
return f.val, f.err
}
self.cond.Wait()
f.cond.Wait()
}
}
// Fired returns whether or not a value has been set. If Fired is true, Get
// won't block.
func (self *Future) Fired() bool {
self.mutex.Lock()
defer self.mutex.Unlock()
return self.received
func (f *Future) Fired() bool {
f.mutex.Lock()
defer f.mutex.Unlock()
return f.received
}
// Set provides the value to present and future Get calls. If Set has already
// been called, this is a no-op.
func (self *Future) Set(val interface{}, err error) {
self.mutex.Lock()
defer self.mutex.Unlock()
if self.received {
func (f *Future) Set(val interface{}, err error) {
f.mutex.Lock()
defer f.mutex.Unlock()
if f.received {
return
}
self.received = true
self.val = val
self.err = err
self.cond.Broadcast()
f.received = true
f.val = val
f.err = err
f.cond.Broadcast()
}