Skip to content

Commit 961c865

Browse files
authored
fix golints G114 and package-comments (openservicemesh#5037)
golints addressed: 1. G114: Use of net/http serve function that has no support for setting timeouts 2. package-comments 3. removes pkg mesh and moves isValidUUID() to pkg/cli/proxy_get.go Signed-off-by: Shalier Xia <[email protected]>
1 parent 2d94011 commit 961c865

File tree

19 files changed

+54
-21
lines changed

19 files changed

+54
-21
lines changed

.golangci.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
run:
22
tests: true
3-
timeout: 10m
3+
timeout: 20m
44
skip-dirs:
55
- pkg/gen
66
skip-files:
@@ -35,6 +35,10 @@ issues:
3535
- revive
3636
source: ". \"github.com/openservicemesh/osm/tests/framework\""
3737
text: "dot imports"
38+
# Ignore error for package comments
39+
- linters:
40+
- revive
41+
text: "package-comments: should have a package comment"
3842
# Exclude staticcheck messages for deprecated function, variable or constant
3943
# This causes issues with package github.com/golang/protobuf/proto
4044
- linters:

demo/cmd/bookbuyer/bookbuyer.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package main implements the bookbuyer application
12
package main
23

34
import (
@@ -77,6 +78,7 @@ func debugServer() {
7778
}
7879
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {})
7980
log.Info().Msgf("Web server running on port %d", *port)
81+
//#nosec G114: Use of net/http serve function that has no support for setting timeouts
8082
err = http.ListenAndServe(fmt.Sprintf(":%d", *port), router)
8183
log.Fatal().Err(err).Msgf("Failed to start HTTP server on port %d", *port)
8284
}

demo/cmd/bookstore/bookstore.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package main implements the bookstore application
12
package main
23

34
import (
@@ -164,8 +165,8 @@ func main() {
164165
router.HandleFunc(h.path, h.fn).Methods(h.method)
165166
}
166167
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {})
167-
168168
log.Info().Msgf("Bookstore running on port %d", *port)
169+
//#nosec G114: Use of net/http serve function that has no support for setting timeouts
169170
err = http.ListenAndServe(fmt.Sprintf(":%d", *port), router)
170171
log.Fatal().Err(err).Msgf("Failed to start HTTP server on port %d", *port)
171172
}

demo/cmd/bookthief/bookthief.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package main implements the bookthief application
12
package main
23

34
import (
@@ -86,6 +87,7 @@ func debugServer() {
8687
}
8788
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {})
8889
log.Info().Msgf("Bookthief running on port %d", *port)
90+
//#nosec G114: Use of net/http serve function that has no support for setting timeouts
8991
err = http.ListenAndServe(fmt.Sprintf(":%d", *port), router)
9092
log.Fatal().Err(err).Msgf("Failed to start HTTP server on port %d", *port)
9193
}

demo/cmd/bookwarehouse/bookwarehouse.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Package main implements the bookwarehouse application
2+
// This create a service which has both inbound as well as outbound service policies
3+
// i.e. bookbuyer makes a GET call to bookstore, bookstore makes a POST call to bookwarehouse
14
package main
25

36
import (
@@ -129,6 +132,7 @@ func main() {
129132
router.HandleFunc("/", restockBooks).Methods("POST")
130133
http.HandleFunc("/favicon.ico", func(w http.ResponseWriter, r *http.Request) {})
131134
log.Info().Msgf("Starting BookWarehouse HTTP server on port %d", *port)
135+
//#nosec G114: Use of net/http serve function that has no support for setting timeouts
132136
err := http.ListenAndServe(fmt.Sprintf(":%d", *port), router)
133137
log.Fatal().Err(err).Msgf("Failed to start BookWarehouse HTTP server on port %d", *port)
134138
}

demo/cmd/bookwatcher/bookwatcher.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package main implements the bookwatcher for terminal and JSON output from demo applications
12
package main
23

34
import (

demo/cmd/common/books.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package common implements shared functions and structs between various book* applications
12
package common
23

34
import (

demo/cmd/database/mysql.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Package database allows the bookwarehouse service to store
2+
// total books data into MySQL persistent storage
13
package database
24

35
import (

mockspec/generate.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Package mockspec allows the mocks to be generated consistently by doing the following:
2+
// 1. defining mockgen rules using a file to specify the parameters
3+
// 2. generating mocks the same way for each of the rules
4+
// 3. integrating checks for the mocks in the CI
15
package main
26

37
import (

pkg/auth/types.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package auth implements the ExtAuthConfig struct.
12
package auth
23

34
import (

pkg/certificate/castorage/k8s/k8s.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package k8s implements helper functions to get certificates from Kubernetes secret
12
package k8s
23

34
import (

pkg/certificate/providers/tresor/fake/fake.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package fake moves fakes to their own sub-package
12
package fake
23

34
import (

pkg/envoy/secrets/errors.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package secrets contains SDSCert types and methods
12
package secrets
23

34
import (

pkg/k8s/fake/fake.go

-19
This file was deleted.

pkg/k8s/informers/informers.go

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Package informers centralize informers by creating a single object that
2+
// runs a set of informers, instead of creating different objects
3+
// that each manage their own informer collections.
4+
// A pointer to this object is then shared with all objects that need it.
15
package informers
26

37
import (

pkg/models/healthprobe.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package models implements the HealthProbe struct.
12
package models
23

34
import "time"

pkg/protobuf/util.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package protobuf contains function(s) pertaining to protobufs
12
package protobuf
23

34
import (

pkg/ticker/ticker.go

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Package ticker reintroduces the ticker concept.
2+
// It contains a ticker implementation that is fully interacted through pubsub.
3+
// It starts turned off by default and is run after dispatcher starts.
14
package ticker
25

36
import (

pkg/workerpool/workerpool.go

+18
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
// Package workerpool implements the thread-pool paradigm
2+
// in Go. The benefits of it in Go however, can be quite different
3+
// from any other language able to schedule itself on system threads.
4+
//
5+
// By using a workpool model, the main focus and intention is to limit the
6+
// number of go routines that can do busy-work and get scheduled concurrenly
7+
// at any point in time.
8+
//
9+
// Too many go routines being scheduled at the same time will cause other
10+
// go routines (maybe more critical ones) to be scheduled less often, thus
11+
// incurring in resource starvation on those and potentially triggering other
12+
// issues.
13+
//
14+
// By being able to queue up work, we should be able to run a more deterministic
15+
// runtime (despite Go's nature, this we will not be able to help), less dependant
16+
// on the scheduler and more accurate in terms of time, as now the number of routines
17+
// doing busy work can remain constant as opposed have O(N) routines attempting to run
18+
// at the same time.
119
package workerpool
220

321
import (

0 commit comments

Comments
 (0)