Browse Source

golint -> staticcheck and required changes

drone
Dan Ballard 3 weeks ago
parent
commit
7fbe110361
  1. 6
      .drone.yml
  2. 12
      metrics/metrics.go
  3. 2
      metrics/monitors.go
  4. 7
      server.go
  5. 2
      storage/message_store.go
  6. 2
      testing/quality.sh

6
.drone.yml

@ -10,7 +10,8 @@ steps:
- name: deps
path: /go
commands:
- go get -u golang.org/x/lint/golint
#- go get -u golang.org/x/lint/golint
- go install honnef.co/go/tools/cmd/staticcheck@latest
- git fetch --tags
- go get
- echo `git describe --tags` > VERSION
@ -23,7 +24,7 @@ steps:
path: /go
commands:
- go list ./... | xargs go vet
- go list ./... | xargs golint -set_exit_status
- staticcheck ./...
- name: units-tests
image: golang
@ -92,7 +93,6 @@ steps:
path: /go
commands:
- export PATH=$PATH:/usr/local/go/bin
- go get -u golang.org/x/lint/golint
- go get
- name: units-tests

12
metrics/metrics.go

@ -179,9 +179,7 @@ func reportLine(t MonitorType, array []float64) string {
func (mh *monitorHistory) returnCopy(slice []float64) []float64 {
retSlice := make([]float64, len(slice))
mh.lock.Lock()
for i, v := range slice {
retSlice[i] = v
}
copy(retSlice, slice)
mh.lock.Unlock()
return retSlice
}
@ -219,22 +217,22 @@ func (mh *monitorHistory) monitorThread() {
minuteAvg := rotateAndAccumulate(mh.perMinutePerHour[:], mh.monitor(), mh.monitorAccumulation)
if time.Now().Sub(mh.timeLastHourRotate) > time.Hour {
if time.Since(mh.timeLastHourRotate) > time.Hour {
rotateAndAccumulate(mh.perHourForDay[:], minuteAvg, mh.monitorAccumulation)
mh.timeLastHourRotate = time.Now()
}
if time.Now().Sub(mh.timeLastDayRotate) > time.Hour*24 {
if time.Since(mh.timeLastDayRotate) > time.Hour*24 {
rotateAndAccumulate(mh.perDayForWeek[:], accumulate(mh.perHourForDay[:], mh.monitorAccumulation), mh.monitorAccumulation)
mh.timeLastDayRotate = time.Now()
}
if time.Now().Sub(mh.timeLastWeekRotate) > time.Hour*24*7 {
if time.Since(mh.timeLastWeekRotate) > time.Hour*24*7 {
rotateAndAccumulate(mh.perWeekForMonth[:], accumulate(mh.perDayForWeek[:], mh.monitorAccumulation), mh.monitorAccumulation)
mh.timeLastWeekRotate = time.Now()
}
if time.Now().Sub(mh.timeLastMonthRotate) > time.Hour*24*7*4 {
if time.Since(mh.timeLastMonthRotate) > time.Hour*24*7*4 {
rotateAndAccumulate(mh.perMonthForYear[:], accumulate(mh.perWeekForMonth[:], mh.monitorAccumulation), mh.monitorAccumulation)
mh.timeLastMonthRotate = time.Now()
}

2
metrics/monitors.go

@ -90,7 +90,7 @@ func (mp *Monitors) report() {
w := bufio.NewWriter(f)
fmt.Fprintf(w, "Uptime: %v\n\n", time.Now().Sub(mp.starttime))
fmt.Fprintf(w, "Uptime: %v\n\n", time.Since(mp.starttime))
fmt.Fprintln(w, "messages:")
mp.Messages.Report(w)

7
server.go

@ -87,8 +87,7 @@ func (s *server) Run(acn connectivity.ACN) error {
}
identity := primitives.InitializeIdentity("", &s.config.PrivateKey, &s.config.PublicKey)
var service tapir.Service
service = new(tor2.BaseOnionService)
service := new(tor2.BaseOnionService)
service.Init(acn, s.config.PrivateKey, &identity)
s.service = service
log.Infof("cwtch server running on cwtch:%s\n", s.Onion())
@ -138,7 +137,7 @@ func (s *server) KeyBundle() *model.KeyBundle {
func (s *server) CheckStatus() (bool, error) {
s.lock.RLock()
defer s.lock.RUnlock()
if s.onionServiceStopped == true || s.tokenServiceStopped == true {
if s.onionServiceStopped || s.tokenServiceStopped {
return s.running, fmt.Errorf("one of more server components are down: onion:%v token service: %v", s.onionServiceStopped, s.tokenServiceStopped)
}
return s.running, nil
@ -192,7 +191,7 @@ func (s *server) Delete(password string) error {
if s.config.Encrypted && !s.config.CheckPassword(password) {
s.lock.Unlock()
log.Errorf("encryped and checkpassword failed")
return errors.New("Cannot delete server, passwords do not match")
return errors.New("cannot delete server, passwords do not match")
}
s.lock.Unlock()
s.Destroy()

2
storage/message_store.go

@ -64,7 +64,7 @@ func (s SqliteMessageStore) FetchMessages() []*groups.EncryptedGroupMessage {
func (s SqliteMessageStore) FetchMessagesFrom(signature []byte) []*groups.EncryptedGroupMessage {
// If signature is empty then treat this as a complete sync request
if signature == nil || len(signature) == 0 {
if len(signature) == 0 {
return s.FetchMessages()
}

2
testing/quality.sh

@ -9,7 +9,7 @@ go list ./... | xargs go vet
echo ""
echo "Linting:"
go list ./... | xargs golint
staticcheck ./...
echo "Time to format"

Loading…
Cancel
Save