Skip to content

Commit

Permalink
staticcheck fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
egonelbre committed Jul 12, 2023
1 parent 0e1ab4b commit dadfd5b
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Go package

on: [push]

jobs:
build:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 'stable'

- name: Build
run: 'go build -v ./...'

- name: Test
run: 'go test -v ./...'
3 changes: 1 addition & 2 deletions conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bytes"
"flag"
"io/ioutil"
"log"
"os"
"regexp"
Expand Down Expand Up @@ -98,7 +97,7 @@ func NewConf(configFile string) *Conf {
return conf
}

data, err := ioutil.ReadFile(configFile)
data, err := os.ReadFile(configFile)
if err != nil {
log.Println("Unable to read configuration file: ", configFile)
log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion debugger/debugger.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ handling:
}
case cmd := <-d.Commands:
tokens := strings.Split(cmd, " ")
action := d.Handler(d, tokens[0], tokens[1:len(tokens)])
action := d.Handler(d, tokens[0], tokens[1:])
action.Exec(d)
case <-d.Watch:
d.Watch <- 1
Expand Down
3 changes: 1 addition & 2 deletions runtime.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"log"
"os"
"runtime"
Expand Down Expand Up @@ -44,7 +43,7 @@ func setMemLimit(setup *AppSetup) {
setup.Extender = func(q *Query) Querys {
runtime.ReadMemStats(m)
if m.Alloc/mb > memLimit {
panic(errors.New("MEMORY LIMIT EXCEEDED!"))
panic("memory limit exceeded!")
}
return ext(q)
}
Expand Down
4 changes: 2 additions & 2 deletions search/features/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ func Get(name string) (CreateFunc, bool) {
func CallCreateWithArgs(function CreateFunc, args []interface{}) (Feature, error) {
fn, fnType, ok := functionAndType(function)
if !ok {
return nil, fmt.Errorf("Argument is not a function!")
return nil, fmt.Errorf("argument is not a function")
}

if fnType.NumIn() != len(args) {
return nil, fmt.Errorf("Invalid number of arguments, requires %v", fnType.NumIn())
return nil, fmt.Errorf("invalid number of arguments, requires %v", fnType.NumIn())
}

arguments := make([]reflect.Value, fnType.NumIn())
Expand Down
10 changes: 5 additions & 5 deletions search/query.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package search

import (
"bytes"
"strings"

"github.com/egonelbre/spexs2/set"
"github.com/egonelbre/spexs2/set/array"
Expand Down Expand Up @@ -98,18 +98,18 @@ func (q *Query) StringLong() string {
}

func (q *Query) StringRaw() string {
buf := bytes.NewBufferString("")
var buf strings.Builder
for _, tok := range q.Pat {
if tok.Flags&IsStar != 0 {
buf.WriteString("*")
}
buf.WriteRune(rune(tok.Token))
}
return string(buf.Bytes())
return buf.String()
}

func (q *Query) string(short bool) string {
buf := bytes.NewBufferString("")
var buf strings.Builder
db := q.Db
for i, tok := range q.Pat {
if tok.Flags&IsStar != 0 {
Expand Down Expand Up @@ -137,5 +137,5 @@ func (q *Query) string(short bool) string {
}
}

return string(buf.Bytes())
return buf.String()
}
5 changes: 3 additions & 2 deletions set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ func testMemoryUse(set Set, n int, t *testing.T) {
before := new(runtime.MemStats)
runtime.ReadMemStats(before)

rand.Seed(5)
rng := rand.New(rand.NewSource(5))

last := 0
for i := 0; i < n; i++ {
last += 10 + rand.Intn(20)
last += 10 + rng.Intn(20)
set.Add(last)
}

Expand Down

0 comments on commit dadfd5b

Please sign in to comment.