Skip to content

Commit 8d14fa3

Browse files
authored
Merge pull request #46 from LandonTClipp/options
Add options for walk constructor, improve CI/CD
2 parents 75111f7 + 8405efd commit 8d14fa3

File tree

5 files changed

+145
-2
lines changed

5 files changed

+145
-2
lines changed

.github/workflows/testing.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Go Test
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
runs-on: ${{ matrix.os }}
12+
strategy:
13+
matrix:
14+
os: [ macos-latest, ubuntu-latest]
15+
go_vers: ['1.20']
16+
steps:
17+
- uses: actions/checkout@v2
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Set up Go
22+
uses: actions/setup-go@v2
23+
with:
24+
go-version: ${{ matrix.go_vers }}
25+
26+
- name: Download dependencies
27+
run: go mod download -x
28+
29+
- name: Test
30+
run: make test.ci
31+
32+
- name: Upload coverage to codecov
33+
uses: codecov/codecov-action@v2
34+
with:
35+
token: ${{ secrets.CODECOV_TOKEN }}
36+
files: ./coverage.txt
37+
verbose: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
coverage.txt

.golangci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
linters:
2+
# Disable all linters.
3+
# Default: false
4+
disable-all: true
5+
# Enable specific linter
6+
# https://golangci-lint.run/usage/linters/#enabled-by-default
7+
enable:
8+
- errcheck
9+
- gosimple
10+
- govet
11+
- ineffassign
12+
- staticcheck
13+
- typecheck
14+
- contextcheck
15+
- durationcheck
16+
- exportloopref
17+
- gocheckcompilerdirectives
18+
- gosec
19+
- loggercheck
20+
- nilerr
21+
- prealloc
22+
- predeclared
23+
- reassign
24+
linters-settings:
25+
staticcheck:
26+
checks:
27+
- all
28+
- '-SA1024'

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
SHELL=bash
2+
3+
.PHONY: all
4+
all: fmt mocks test install docker
5+
6+
.PHONY: fmt
7+
fmt:
8+
go fmt ./...
9+
10+
.PHONY: test
11+
test:
12+
go test -v -coverprofile=coverage.txt ./...
13+
14+
.PHONY: test.ci
15+
test.ci: test fmt
16+
17+
.PHONY: lint
18+
lint:
19+
go run github.com/golangci/golangci-lint/cmd/[email protected] run
20+
21+
.PHONY: clean
22+
clean:
23+
rm -rf mocks

walk.go

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,63 @@ type Walk struct {
102102
root *Path
103103
}
104104

105+
type WalkOptsFunc func(config *WalkOpts)
106+
107+
func WalkDepth(depth int) WalkOptsFunc {
108+
return func(config *WalkOpts) {
109+
config.Depth = depth
110+
}
111+
}
112+
113+
func WalkAlgorithm(algo Algorithm) WalkOptsFunc {
114+
return func(config *WalkOpts) {
115+
config.Algorithm = algo
116+
}
117+
}
118+
119+
func WalkFollowSymlinks(follow bool) WalkOptsFunc {
120+
return func(config *WalkOpts) {
121+
config.FollowSymlinks = follow
122+
}
123+
}
124+
125+
func WalkMinimumFileSize(size int64) WalkOptsFunc {
126+
return func(config *WalkOpts) {
127+
config.MinimumFileSize = size
128+
}
129+
}
130+
131+
func WalkMaximumFileSize(size int64) WalkOptsFunc {
132+
return func(config *WalkOpts) {
133+
config.MaximumFileSize = size
134+
}
135+
}
136+
137+
func WalkVisitFiles(value bool) WalkOptsFunc {
138+
return func(config *WalkOpts) {
139+
config.VisitFiles = value
140+
}
141+
}
142+
143+
func WalkVisitDirs(value bool) WalkOptsFunc {
144+
return func(config *WalkOpts) {
145+
config.VisitDirs = value
146+
}
147+
}
148+
149+
func WalkVisitSymlinks(value bool) WalkOptsFunc {
150+
return func(config *WalkOpts) {
151+
config.VisitSymlinks = value
152+
}
153+
}
154+
105155
// NewWalk returns a new Walk struct with default values applied
106-
func NewWalk(root *Path) (*Walk, error) {
107-
return NewWalkWithOpts(root, DefaultWalkOpts())
156+
func NewWalk(root *Path, opts ...WalkOptsFunc) (*Walk, error) {
157+
config := DefaultWalkOpts()
158+
for _, opt := range opts {
159+
opt(config)
160+
}
161+
return NewWalkWithOpts(root, config)
108162
}
109163

110164
// NewWalkWithOpts returns a Walk object with the given WalkOpts applied

0 commit comments

Comments
 (0)