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
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ jobs:
cat $GITHUB_WORKSPACE/profile.cov_tmp | grep -v "_mock.go" > $GITHUB_WORKSPACE/profile.cov

- name: golangci-lint
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v7
with:
version: latest
version: v2.0.2

- name: install goveralls
run: |
GO111MODULE=off go get -u -v github.com/mattn/goveralls

- name: submit coverage
run: $(go env GOPATH)/bin/goveralls -service="github" -coverprofile=$GITHUB_WORKSPACE/profile.cov
continue-on-error: true
env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
124 changes: 65 additions & 59 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,65 +1,71 @@
linters-settings:
govet:
enable:
- shadow
golint:
min-confidence: 0.8
gocyclo:
min-complexity: 15
maligned:
suggest-new: true
dupl:
threshold: 100
goconst:
min-len: 2
min-occurrences: 2
misspell:
locale: US
lll:
line-length: 140
gocritic:
enabled-tags:
- performance
- style
- experimental
disabled-checks:
- wrapperFunc
- hugeParam
- rangeValCopy

version: "2"
run:
tests: false
linters:
disable-all: true
default: none
enable:
- megacheck
- revive
- copyloopvar
- dupl
- gochecknoinits
- gocritic
- gosec
- govet
- unconvert
- megacheck
- unused
- gas
- gocyclo
- misspell
- unparam
- typecheck
- ineffassign
- stylecheck
- gochecknoinits
- misspell
- nakedret
- gosimple
- prealloc

fast: false


run:
# modules-download-mode: vendor
skip-dirs:
- vendor
concurrency: 4

issues:
exclude-rules:
- text: "weak cryptographic primitive"
linters:
- gosec
exclude-use-default: false
- revive
- staticcheck
- unconvert
- unparam
- unused
settings:
goconst:
min-len: 2
min-occurrences: 2
gocritic:
disabled-checks:
- wrapperFunc
- hugeParam
- rangeValCopy
- singleCaseSwitch
- ifElseChain
enabled-tags:
- performance
- style
- experimental
govet:
enable:
- shadow
lll:
line-length: 140
misspell:
locale: US
exclusions:
generated: lax
rules:
- linters:
- staticcheck
text: at least one file in a package should have a package comment
- linters:
- revive
text: should have a package comment
- linters:
- dupl
- gosec
path: _test\.go
paths:
- vendor
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
exclusions:
generated: lax
paths:
- vendor
- third_party$
- builtin$
- examples$
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,88 @@ Package `fileutils` provides useful, high-level file operations.
- `TempFileName` returns a new temporary file name using secure random generation
- `SanitizePath` cleans file path
- `TouchFile` creates an empty file or updates timestamps of existing one
- `Checksum` calculates file checksum using various hash algorithms (MD5, SHA1, SHA256, etc.)
- `FileWatcher` watches files or directories for changes
- `WatchRecursive` watches a directory recursively for changes

## Usage Examples

### File Operations

```go
// Copy a file
err := fileutils.CopyFile("source.txt", "destination.txt")
if err != nil {
log.Fatalf("Failed to copy file: %v", err)
}

// Move a file
err = fileutils.MoveFile("source.txt", "destination.txt")
if err != nil {
log.Fatalf("Failed to move file: %v", err)
}

// Check if a file or directory exists
if fileutils.IsFile("file.txt") {
fmt.Println("File exists")
}
if fileutils.IsDir("directory") {
fmt.Println("Directory exists")
}

// Generate a temporary file name
tempName, err := fileutils.TempFileName("/tmp", "prefix-*.ext")
if err != nil {
log.Fatalf("Failed to generate temp file name: %v", err)
}
fmt.Println("Temp file:", tempName)
```

### File Checksum

```go
// Calculate MD5 checksum
md5sum, err := fileutils.Checksum("path/to/file", enum.HashAlgMD5)
if err != nil {
log.Fatalf("Failed to calculate MD5: %v", err)
}
fmt.Printf("MD5: %s\n", md5sum)

// Calculate SHA256 checksum
sha256sum, err := fileutils.Checksum("path/to/file", enum.HashAlgSHA256)
if err != nil {
log.Fatalf("Failed to calculate SHA256: %v", err)
}
fmt.Printf("SHA256: %s\n", sha256sum)
```

### File Watcher

```go
// Create a simple file watcher
watcher, err := fileutils.NewFileWatcher("/path/to/file", func(event FileEvent) {
fmt.Printf("Event: %s, Path: %s\n", event.Type, event.Path)
})
if err != nil {
log.Fatalf("Failed to create watcher: %v", err)
}
defer watcher.Close()

// Watch a directory recursively
watcher, err := fileutils.WatchRecursive("/path/to/dir", func(event FileEvent) {
fmt.Printf("Event: %s, Path: %s\n", event.Type, event.Path)
})
if err != nil {
log.Fatalf("Failed to create watcher: %v", err)
}
defer watcher.Close()

// Add another path to an existing watcher
err = watcher.AddPath("/path/to/another/file")

// Remove a path from the watcher
err = watcher.RemovePath("/path/to/file")
```

## Install and update

Expand Down
119 changes: 119 additions & 0 deletions enum/event_type_enum.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading