Skip to content

Commit

Permalink
cleanup: lint go code
Browse files Browse the repository at this point in the history
at present 202 problems (51 errors) (151 warnings)
  • Loading branch information
Pranay0302 committed Jan 30, 2021
1 parent 171f921 commit 04c69b1
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 35 deletions.
4 changes: 1 addition & 3 deletions examples/golang/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import (
"github.com/pyroscope-io/pyroscope/pkg/agent/profiler"
)

func work(n int) {
for i := 0; i < n; i++ {
func work(int) {

}
}

func fastFunction() {
Expand Down
4 changes: 2 additions & 2 deletions pkg/agent/gospy/gospy.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ type GoSpy struct {
selfFrame *runtime.Frame
}

func Start(_pid int) (spy.Spy, error) {
func Start(_ int) (spy.Spy, error) {
return &GoSpy{}, nil
}

func (s *GoSpy) Stop() error {
func (*GoSpy) Stop() error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/selfprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/sirupsen/logrus"
)

func SelfProfile(cfg *config.Config, u upstream.Upstream, appName string) {
func SelfProfile(_ *config.Config, u upstream.Upstream, appName string) {
// TODO: add sample rate
s := NewSession(u, appName, "gospy", 100, 0, false)
err := s.Start()
Expand Down
6 changes: 3 additions & 3 deletions pkg/exec/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,12 @@ func generateSeed(args []string) string {

func generateCredentialsDrop() (*syscall.Credential, error) {
sudoUser := os.Getenv("SUDO_USER")
sudoUid := os.Getenv("SUDO_UID")
sudoUID := os.Getenv("SUDO_UID")
sudoGid := os.Getenv("SUDO_GID")

logrus.Infof("dropping permissions, running command as %q (%s/%s)", sudoUser, sudoUid, sudoGid)
logrus.Infof("dropping permissions, running command as %q (%s/%s)", sudoUser, sudoUID, sudoGid)

uid, err := strconv.Atoi(sudoUid)
uid, err := strconv.Atoi(sudoUID)
if err != nil {
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/server/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ func renderServerError(rw http.ResponseWriter, text string) {
rw.Write([]byte("\n"))
}

type indexPageJson struct {
type indexPageJSON struct {
AppNames []string `json:"appNames"`
}

type buildInfoJson struct {
type bi struct {
GOOS string `json:"goos"`
GOARCH string `json:"goarch"`
Version string `json:"version"`
Expand All @@ -121,7 +121,7 @@ type indexPage struct {
ExtraMetadata string
}

func (ctrl *Controller) renderIndexPage(dir http.FileSystem, rw http.ResponseWriter, r *http.Request) {
func (ctrl *Controller) renderIndexPage(dir http.FileSystem, rw http.ResponseWriter, _ *http.Request) {
f, err := dir.Open("/index.html")
if err != nil {
renderServerError(rw, fmt.Sprintf("could not find file index.html: %q", err))
Expand All @@ -140,7 +140,7 @@ func (ctrl *Controller) renderIndexPage(dir http.FileSystem, rw http.ResponseWri
return
}

initialStateObj := indexPageJson{}
initialStateObj := indexPageJSON{}
ctrl.s.GetValues("__name__", func(v string) bool {
initialStateObj.AppNames = append(initialStateObj.AppNames, v)
return true
Expand All @@ -152,7 +152,7 @@ func (ctrl *Controller) renderIndexPage(dir http.FileSystem, rw http.ResponseWri
}
initialStateStr := string(b)

buildInfoObj := buildInfoJson{
buildInfoObj := bi{
GOOS: runtime.GOOS,
GOARCH: runtime.GOARCH,
Version: build.Version,
Expand Down
4 changes: 2 additions & 2 deletions pkg/server/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"net/http"
)

func (ctrl *Controller) labelsHandler(w http.ResponseWriter, r *http.Request) {
func (ctrl *Controller) labelsHandler(w http.ResponseWriter, _ *http.Request) {
res := []string{}
ctrl.s.GetKeys(func(k string) bool {
res = append(res, k)
Expand All @@ -19,7 +19,7 @@ func (ctrl *Controller) labelsHandler(w http.ResponseWriter, r *http.Request) {
w.Write(b)
}

func (ctrl *Controller) labelValuesHandler(w http.ResponseWriter, r *http.Request) {
func (ctrl *Controller) labelValuesHandler(w http.ResponseWriter, _ *http.Request) {
res := []string{}
labelName := r.URL.Query().Get("label")
ctrl.s.GetValues(labelName, func(v string) bool {
Expand Down
1 change: 0 additions & 1 deletion pkg/storage/dict/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ OuterLoop:
continue OuterLoop
} else {
// 2

varint.Write(w, uint64(leadIndex))
varint.Write(w, uint64(len(leadKey)))
return
Expand Down
6 changes: 5 additions & 1 deletion pkg/storage/dimension/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ func (s *Dimension) Serialize(w io.Writer) error {

for _, k := range s.keys {
varint.Write(w, uint64(len(k)))
w.Write([]byte(k))
if err != nil {
return nil
} else {
w.Write([]byte(k))
}
}
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/labels/labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Labels struct {
db *badger.DB
}

func New(cfg *config.Config, db *badger.DB) *Labels {
func New(_, db *badger.DB) *Labels {
ll := &Labels{
db: db,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/segment/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (sn *streeNode) findAddons() []Addon {
return res
}

func (sn *streeNode) put(st, et time.Time, samples uint64, cb func(n *streeNode, depth int, dt time.Time, r *big.Rat, addons []Addon)) {
func (sn *streeNode) put(st, et time.Time, _ uint64, cb func(n *streeNode, depth int, dt time.Time, r *big.Rat, addons []Addon)) {
nodes := []*streeNode{sn}

for len(nodes) > 0 {
Expand Down
3 changes: 0 additions & 3 deletions pkg/storage/segment/segment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,10 @@ var _ = Describe("stree", func() {

It("works with 3 mins", func() {
s := New(r, m)

s.Put(testing.SimpleTime(10), testing.SimpleTime(70), 1, func(de int, t time.Time, r *big.Rat, a []Addon) {})
Expect(s.root).ToNot(BeNil())
Expect(s.root.depth).To(Equal(1))

spew.Dump(s.root)

// Expect(doGet(s, testing.SimpleTime(20, testing.SimpleTime(49))).To(HaveLen(3))
})

Expand Down
8 changes: 4 additions & 4 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/sirupsen/logrus"
)

var closingErr = errors.New("the db is in closing state")
var errFoo = errors.New("the db is in closing state")

type Storage struct {
closingMutex sync.Mutex
Expand Down Expand Up @@ -171,7 +171,7 @@ func (s *Storage) Put(startTime, endTime time.Time, key *Key, val *tree.Tree, sp
defer s.closingMutex.Unlock()

if s.closing {
return closingErr
return errFoo
}
logrus.WithFields(logrus.Fields{
"startTime": startTime.String(),
Expand Down Expand Up @@ -218,7 +218,7 @@ func (s *Storage) Get(startTime, endTime time.Time, key *Key) (*tree.Tree, *segm
defer s.closingMutex.Unlock()

if s.closing {
return nil, nil, "", 100, closingErr
return nil, nil, "", 100, errFoo
}

logrus.WithFields(logrus.Fields{
Expand Down Expand Up @@ -308,7 +308,7 @@ func (s *Storage) DiskUsage() map[string]bytesize.ByteSize {
"dimensions": 0,
"segments": 0,
}
for k, _ := range res {
for k := range res {
res[k] = dirSize(filepath.Join(s.cfg.Server.StoragePath, k))
}
return res
Expand Down
1 change: 0 additions & 1 deletion pkg/storage/tree/serialize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ var _ = Describe("tree package", func() {
It("returns correct results", func() {
Expect(tree.root.ChildrenNodes).To(HaveLen(1))
})

})

Context("trie.Serialize(d, )", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/tree/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (tn *treeNode) insert(targetLabel []byte) *treeNode {
return tn.ChildrenNodes[i]
}

func (t *Tree) Insert(key []byte, value uint64, merge ...bool) {
func (t *Tree) Insert(key []byte, value uint64, _ ...bool) {
t.m.Lock()
defer t.m.Unlock()

Expand Down
1 change: 0 additions & 1 deletion pkg/structs/cappedarr/cappedarr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var _ = Describe("cappedarr", func() {
defer GinkgoRecover()
Context("simple case", func() {
It("works", func() {

values := []uint64{1, 2, 3, 4, 5, 6}
for i := 0; i < 1000; i++ {
ca := New(4)
Expand Down
2 changes: 1 addition & 1 deletion pkg/structs/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func MergeTriesConcurrently(concurrency int, tries ...Merger) Merger {
return pool[0]
}

func MergeTriesSerially(concurrency int, tries ...Merger) Merger {
func MergeTriesSerially(_ int, tries ...Merger) Merger {
// rand.Shuffle(len(tries), func(i, j int) {
// tries[i], tries[j] = tries[j], tries[i]
// })
Expand Down
1 change: 0 additions & 1 deletion pkg/structs/transporttrie/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ var _ = Describe("trie package", func() {
Expect(buf4).To(Equal(buf3))
}
close(done)

}, 1.0)
})

Expand Down
4 changes: 2 additions & 2 deletions pkg/testing/tmpdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func DirStats(path string) (directories int, files int, size bytesize.ByteSize)
return err
}
if info.IsDir() {
directories += 1
directories++
} else {
files += 1
files++
size += bytesize.ByteSize(info.Size())
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/attime/attime.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Parse(s string) time.Time {
return parseTimeReference(ref).Add(parseTimeOffset(offset))
}

func parseTimeReference(ref string) time.Time {
func parseTimeReference(_ string) time.Time {
now := time.Now()
// TODO: implement
return now
Expand Down

0 comments on commit 04c69b1

Please sign in to comment.