Skip to content

Commit

Permalink
Merge pull request #46 from LandonTClipp/options
Browse files Browse the repository at this point in the history
Add options for walk constructor, improve CI/CD
  • Loading branch information
LandonTClipp authored Apr 8, 2023
2 parents 75111f7 + 8405efd commit 8d14fa3
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 2 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Go Test

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ macos-latest, ubuntu-latest]
go_vers: ['1.20']
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go_vers }}

- name: Download dependencies
run: go mod download -x

- name: Test
run: make test.ci

- name: Upload coverage to codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.txt
verbose: true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage.txt
28 changes: 28 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
linters:
# Disable all linters.
# Default: false
disable-all: true
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- contextcheck
- durationcheck
- exportloopref
- gocheckcompilerdirectives
- gosec
- loggercheck
- nilerr
- prealloc
- predeclared
- reassign
linters-settings:
staticcheck:
checks:
- all
- '-SA1024'
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SHELL=bash

.PHONY: all
all: fmt mocks test install docker

.PHONY: fmt
fmt:
go fmt ./...

.PHONY: test
test:
go test -v -coverprofile=coverage.txt ./...

.PHONY: test.ci
test.ci: test fmt

.PHONY: lint
lint:
go run github.com/golangci/golangci-lint/cmd/[email protected] run

.PHONY: clean
clean:
rm -rf mocks
58 changes: 56 additions & 2 deletions walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,63 @@ type Walk struct {
root *Path
}

type WalkOptsFunc func(config *WalkOpts)

func WalkDepth(depth int) WalkOptsFunc {
return func(config *WalkOpts) {
config.Depth = depth
}
}

func WalkAlgorithm(algo Algorithm) WalkOptsFunc {
return func(config *WalkOpts) {
config.Algorithm = algo
}
}

func WalkFollowSymlinks(follow bool) WalkOptsFunc {
return func(config *WalkOpts) {
config.FollowSymlinks = follow
}
}

func WalkMinimumFileSize(size int64) WalkOptsFunc {
return func(config *WalkOpts) {
config.MinimumFileSize = size
}
}

func WalkMaximumFileSize(size int64) WalkOptsFunc {
return func(config *WalkOpts) {
config.MaximumFileSize = size
}
}

func WalkVisitFiles(value bool) WalkOptsFunc {
return func(config *WalkOpts) {
config.VisitFiles = value
}
}

func WalkVisitDirs(value bool) WalkOptsFunc {
return func(config *WalkOpts) {
config.VisitDirs = value
}
}

func WalkVisitSymlinks(value bool) WalkOptsFunc {
return func(config *WalkOpts) {
config.VisitSymlinks = value
}
}

// NewWalk returns a new Walk struct with default values applied
func NewWalk(root *Path) (*Walk, error) {
return NewWalkWithOpts(root, DefaultWalkOpts())
func NewWalk(root *Path, opts ...WalkOptsFunc) (*Walk, error) {
config := DefaultWalkOpts()
for _, opt := range opts {
opt(config)
}
return NewWalkWithOpts(root, config)
}

// NewWalkWithOpts returns a Walk object with the given WalkOpts applied
Expand Down

0 comments on commit 8d14fa3

Please sign in to comment.