Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.14
go-version: ^1.25
id: go

- name: Check out code into the Go module directory
Expand All @@ -32,6 +32,5 @@ jobs:
run: go test -race -cover -v ./...

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.49
uses: golangci/golangci-lint-action@v9

4 changes: 1 addition & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
run:
version: '2'

linters:
enable:
- errcheck
- errorlint
- gosimple
- govet
- ineffassign
- typecheck
- unused
- cyclop
- durationcheck
Expand Down
33 changes: 21 additions & 12 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"sync"

"github.com/radovskyb/watcher"
"github.com/fsnotify/fsnotify"
)

const configStructTagName string = "config"
Expand All @@ -26,7 +26,7 @@ type Config struct {
binders []reflect.Value
cache *Values
errch chan error
watch *watcher.Watcher
watch *fsnotify.Watcher
m sync.Mutex
}

Expand All @@ -49,7 +49,7 @@ func New(opts ...Option) *Config {
// Close cleans up channels and file watches.
func (c *Config) Close() {
if c.watch != nil {
c.watch.Close()
_ = c.watch.Close()
}

close(c.errch)
Expand Down Expand Up @@ -273,19 +273,28 @@ func isSliceEqual(as interface{}, bs interface{}) bool {
return true
}

func newFileWatcher(fn func(), errfn func(error)) *watcher.Watcher {
w := watcher.New()
w.SetMaxEvents(1)
w.FilterOps(watcher.Write)
func newFileWatcher(fn func(), errfn func(error)) *fsnotify.Watcher {
w, err := fsnotify.NewWatcher()
if err != nil {
errfn(err)
return nil
}

go func() {
for {
select {
case <-w.Event:
fn()
case <-w.Closed:
return
case err := <-w.Error:
case event, ok := <-w.Events:
if !ok {
return
}
// Only trigger on write events (file modifications)
if event.Has(fsnotify.Write) {
fn()
}
case err, ok := <-w.Errors:
if !ok {
return
}
errfn(err)
}
}
Expand Down
11 changes: 9 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
module github.com/ourstudio-se/binder

go 1.14
go 1.25

require (
github.com/radovskyb/watcher v1.0.7
github.com/fsnotify/fsnotify v1.8.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.13.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/radovskyb/watcher v1.0.7 h1:AYePLih6dpmS32vlHfhCeli8127LzkIgwJGcwwe8tUE=
github.com/radovskyb/watcher v1.0.7/go.mod h1:78okwvY5wPdzcb1UYnip1pvrZNIVEIh/Cm+ZuvsUYIg=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
2 changes: 1 addition & 1 deletion parsers/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (p *FileParser) Parse() (map[string]interface{}, error) {
return nil, err
}

defer h.Close()
defer func() { _ = h.Close() }()

kvp := NewKeyValueParser(h, WithKeyValueSeparator(p.sep))
return kvp.Parse()
Expand Down
2 changes: 1 addition & 1 deletion parsers/k8s-volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (p *KubernetesVolumeParser) Parse() (map[string]interface{}, error) {
}

key := filepath.Base(path)
b, err := os.ReadFile(path)
b, err := os.ReadFile(path) // #nosec G304 -- path is controlled by user-provided volume mount path
if err != nil {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion parsers/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (p *RemoteFileParser) Parse() (map[string]interface{}, error) {
return nil, err
}

defer resp.Body.Close()
defer func() { _ = resp.Body.Close() }()

if resp.StatusCode >= 400 {
return nil, fmt.Errorf("remote server returned unsuccessful status code: %d", resp.StatusCode)
Expand Down