mirror of https://github.com/maxcnunes/gaper.git
Compare commits
21 Commits
Author | SHA1 | Date |
---|---|---|
|
c44dd59952 | |
|
5a02122f33 | |
|
edee55552a | |
|
d314b7b928 | |
|
f0479bba61 | |
|
90f855c72b | |
|
1fde6281f1 | |
|
95fc7d2127 | |
|
b0dcdd49b0 | |
|
39d9c0ad64 | |
|
9229e8d69b | |
|
4eb2525b49 | |
|
7f381c7e58 | |
|
2a09c4e713 | |
|
e99cd89574 | |
|
3f3fcea575 | |
|
0324256f9c | |
|
7c57257db3 | |
|
60a0a90d11 | |
|
2cdb29eb89 | |
|
69ab70821a |
|
@ -0,0 +1,37 @@
|
|||
name: goreleaser
|
||||
|
||||
on:
|
||||
push:
|
||||
# run only against tags
|
||||
tags:
|
||||
- '*'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Fetch all tags
|
||||
run: git fetch --force --tags
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.19
|
||||
-
|
||||
name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v2
|
||||
with:
|
||||
distribution: goreleaser
|
||||
version: latest
|
||||
args: release --rm-dist
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@ -0,0 +1,39 @@
|
|||
name: dev-workflow
|
||||
|
||||
on:
|
||||
- push
|
||||
jobs:
|
||||
run:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os:
|
||||
- ubuntu-latest
|
||||
# - macos-latest
|
||||
# - windows-latest
|
||||
go:
|
||||
- '1.19'
|
||||
# - '1.18'
|
||||
# - '1.17'
|
||||
# - '1.16'
|
||||
# - '1.15'
|
||||
env:
|
||||
OS: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@master
|
||||
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
|
||||
- name: golangci-lint
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
version: v1.48
|
||||
|
||||
- name: Test
|
||||
run: make test
|
||||
|
||||
- name: Upload coverage to Codecov
|
||||
uses: codecov/codecov-action@v3
|
29
.travis.yml
29
.travis.yml
|
@ -1,29 +0,0 @@
|
|||
language: go
|
||||
|
||||
go:
|
||||
# - 1.7.x
|
||||
# - 1.8.x
|
||||
# - 1.9.x
|
||||
- 1.10.x
|
||||
# - master
|
||||
|
||||
before_script:
|
||||
- go version
|
||||
- make setup
|
||||
- make lint
|
||||
|
||||
script:
|
||||
- make test
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
||||
|
||||
notifications:
|
||||
email: false
|
||||
|
||||
deploy:
|
||||
- provider: script
|
||||
skip_cleanup: true
|
||||
script: curl -sL http://git.io/goreleaser | bash
|
||||
on:
|
||||
tags: true
|
|
@ -28,7 +28,13 @@ make setup
|
|||
### Running gaper in development
|
||||
|
||||
```
|
||||
make build && ./gaper --verbose --bin-name srv --build-path ./testdata/server
|
||||
make build && \
|
||||
./gaper \
|
||||
--verbose \
|
||||
--bin-name srv \
|
||||
--build-path ./testdata/server \
|
||||
--build-args="-ldflags=\"-X 'main.Version=v1.0.0'\"" \
|
||||
--extensions "go,txt"
|
||||
```
|
||||
|
||||
### Running lint
|
||||
|
@ -49,3 +55,6 @@ A single test:
|
|||
go test -run TestSimplePost ./...
|
||||
```
|
||||
|
||||
### Release
|
||||
|
||||
The release runs automatically with a Github action on pushed git tags.
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/davecgh/go-spew"
|
||||
packages = ["spew"]
|
||||
revision = "346938d642f2ec3594ed81d874461961cd0faa76"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/fatih/color"
|
||||
packages = ["."]
|
||||
revision = "5b77d2a35fb0ede96d138fc9a99f5c9b6aef11b4"
|
||||
version = "v1.7.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattn/go-colorable"
|
||||
packages = ["."]
|
||||
revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
|
||||
version = "v0.0.9"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattn/go-isatty"
|
||||
packages = ["."]
|
||||
revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
|
||||
version = "v0.0.3"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattn/go-shellwords"
|
||||
packages = ["."]
|
||||
revision = "02e3cf038dcea8290e44424da473dd12be796a8a"
|
||||
version = "v1.0.3"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mattn/go-zglob"
|
||||
packages = [
|
||||
".",
|
||||
"fastwalk"
|
||||
]
|
||||
revision = "49693fbb3fe3c3a75fc4e4d6fb1d7cedcbdeb385"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/pmezard/go-difflib"
|
||||
packages = ["difflib"]
|
||||
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/stretchr/objx"
|
||||
packages = ["."]
|
||||
revision = "477a77ecc69700c7cdeb1fa9e129548e1c1c393c"
|
||||
version = "v0.1.1"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/stretchr/testify"
|
||||
packages = [
|
||||
"assert",
|
||||
"mock"
|
||||
]
|
||||
revision = "f35b8ab0b5a2cef36673838d662e249dd9c94686"
|
||||
version = "v1.2.2"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/urfave/cli"
|
||||
packages = ["."]
|
||||
revision = "cfb38830724cc34fedffe9a2a29fb54fa9169cd1"
|
||||
version = "v1.20.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/sys"
|
||||
packages = ["unix"]
|
||||
revision = "6c888cc515d3ed83fc103cf1d84468aad274b0a7"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "8446ff85ebcb6bc802d3f444727c3910444a405f3c073c1095eb5cc8c497138b"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
23
Gopkg.toml
23
Gopkg.toml
|
@ -1,23 +0,0 @@
|
|||
[[constraint]]
|
||||
name = "github.com/fatih/color"
|
||||
version = "1.7.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/mattn/go-shellwords"
|
||||
version = "1.0.3"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/urfave/cli"
|
||||
version = "1.20.0"
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/mattn/go-zglob"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/stretchr/testify"
|
||||
version = "1.2.2"
|
24
Makefile
24
Makefile
|
@ -3,32 +3,14 @@ TEST_PACKAGES := $(shell go list ./... | grep -v cmd)
|
|||
COVER_PACKAGES := $(shell go list ./... | grep -v cmd | paste -sd "," -)
|
||||
LINTER := $(shell command -v gometalinter 2> /dev/null)
|
||||
|
||||
.PHONY: setup
|
||||
|
||||
setup:
|
||||
ifeq ($(OS), Darwin)
|
||||
brew install dep
|
||||
else
|
||||
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
|
||||
endif
|
||||
dep ensure -vendor-only
|
||||
ifndef LINTER
|
||||
@echo "Installing linter"
|
||||
@go get -u github.com/alecthomas/gometalinter
|
||||
@gometalinter --install
|
||||
endif
|
||||
|
||||
build:
|
||||
@go build -o ./gaper cmd/gaper/main.go
|
||||
|
||||
## lint: Validate golang code
|
||||
# Install it following this doc https://golangci-lint.run/usage/install/#local-installation,
|
||||
# please use the same version from .github/workflows/workflow.yml.
|
||||
lint:
|
||||
@gometalinter \
|
||||
--deadline=120s \
|
||||
--line-length=120 \
|
||||
--enable-all \
|
||||
--disable=gochecknoinits --disable=gochecknoglobals \
|
||||
--vendor ./...
|
||||
@golangci-lint run
|
||||
|
||||
test:
|
||||
@go test -p=1 -coverpkg $(COVER_PACKAGES) \
|
||||
|
|
42
README.md
42
README.md
|
@ -18,15 +18,23 @@
|
|||
[](https://goreportcard.com/report/github.com/maxcnunes/gaper)
|
||||
[](https://github.com/goreleaser)
|
||||
|
||||
## Changelog
|
||||
|
||||
See [Releases](https://github.com/maxcnunes/gaper/releases) for detailed history changes.
|
||||
|
||||
## Installation
|
||||
|
||||
Using go tooling:
|
||||
|
||||
```
|
||||
go get -u github.com/maxcnunes/gaper/cmd/gaper
|
||||
```
|
||||
|
||||
## Changelog
|
||||
Or, downloading the binary instead (example for version 1.1.0, make sure you are using the latest version though):
|
||||
|
||||
See [Releases](https://github.com/maxcnunes/gaper/releases) for detailed history changes.
|
||||
```
|
||||
curl -SL https://github.com/maxcnunes/gaper/releases/download/v1.1.0/gaper_1.1.0_linux_amd64.tar.gz | tar -xvzf - -C "${GOPATH}/bin"
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -53,7 +61,7 @@ GLOBAL OPTIONS:
|
|||
--watch value, -w value list of folders or files to watch for changes
|
||||
--ignore value, -i value list of folders or files to ignore for changes
|
||||
--poll-interval value, -p value how often in milliseconds to poll watched files for changes (default: 500)
|
||||
--extensions value, -e value a comma-delimited list of file extensions to watch for changes (default: "go")
|
||||
--extensions value, -e value extensions to watch for changes (default: "go")
|
||||
--no-restart-on value, -n value don't automatically restart the supervised program if it ends:
|
||||
if "error", an exit code of 0 will still restart.
|
||||
if "exit", no restart regardless of exit code.
|
||||
|
@ -62,7 +70,15 @@ GLOBAL OPTIONS:
|
|||
--version, -v print the version
|
||||
```
|
||||
|
||||
Since in most projects there is no need to watch changes of:
|
||||
### Watch and Ignore paths
|
||||
|
||||
For those options Gaper supports static paths (e.g. `build/`, `seed.go`) or glob paths (e.g. `migrations/**/up.go`, `*_test.go`).
|
||||
|
||||
On using a path to a directory please add a `/` at the end (e.g. `build/`) to make sure Gaper won't include other matches that starts with that same value (e.g. `build/`, `build_settings.go`).
|
||||
|
||||
### Default ignore settings
|
||||
|
||||
Since in most projects there is no need to watch changes for:
|
||||
|
||||
* hidden files and folders
|
||||
* test files (`*_test.go`)
|
||||
|
@ -70,6 +86,10 @@ Since in most projects there is no need to watch changes of:
|
|||
|
||||
Gaper by default ignores those cases already. Although, if you need Gaper to watch those files anyway it is possible to disable this setting with `--disable-default-ignore` argument.
|
||||
|
||||
### Watch method
|
||||
|
||||
Currently Gaper uses polling to watch file changes. We have plans to [support fs events](https://github.com/maxcnunes/gaper/issues/12) though in a near future.
|
||||
|
||||
### Examples
|
||||
|
||||
Using all defaults provided by Gaper:
|
||||
|
@ -78,12 +98,18 @@ Using all defaults provided by Gaper:
|
|||
gaper
|
||||
```
|
||||
|
||||
Ignore watch over all test files:
|
||||
|
||||
> no need for this in case if you are not using `--disable-default-ignore`
|
||||
Example providing a few custom configurations:
|
||||
|
||||
```
|
||||
--ignore './**/*_test.go'
|
||||
gaper \
|
||||
--bin-name build/api-dev \
|
||||
--build-path cmd/server \
|
||||
--build-args "-ldflags=\"-X 'main.Version=dev'" \
|
||||
-w 'public/**' -w '*.go' \
|
||||
-e js -e css -e html \
|
||||
--ignore './**/*_mock.go' \
|
||||
--program-args "-arg1 ok -arg2=nope" \
|
||||
--watch .
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
|
31
appveyor.yml
31
appveyor.yml
|
@ -1,31 +0,0 @@
|
|||
version: "{build}"
|
||||
|
||||
# Source Config
|
||||
|
||||
clone_folder: c:\gopath\src\github.com\maxcnunes\gaper
|
||||
|
||||
# Build host
|
||||
|
||||
environment:
|
||||
GOPATH: c:\gopath
|
||||
GOBIN: c:\gopath\bin
|
||||
|
||||
init:
|
||||
- git config --global core.autocrlf input
|
||||
|
||||
# Build
|
||||
|
||||
install:
|
||||
- set Path=c:\go\bin;c:\gopath\bin;%Path%
|
||||
- go version
|
||||
- go env
|
||||
- go get -u github.com/golang/dep/cmd/dep
|
||||
- choco install make
|
||||
- make setup
|
||||
|
||||
build: false
|
||||
deploy: false
|
||||
|
||||
test_script:
|
||||
- go build github.com/maxcnunes/gaper/cmd/gaper
|
||||
- make test
|
|
@ -17,7 +17,6 @@ type Builder interface {
|
|||
type builder struct {
|
||||
dir string
|
||||
binary string
|
||||
errors string
|
||||
wd string
|
||||
buildArgs []string
|
||||
}
|
||||
|
|
|
@ -38,15 +38,13 @@ func TestBuilderFailureBuild(t *testing.T) {
|
|||
t.Fatalf("couldn't get current working directory: %v", err)
|
||||
}
|
||||
|
||||
absPathBuild := filepath.Join(wd, dir)
|
||||
|
||||
b := NewBuilder(dir, bin, wd, bArgs)
|
||||
err = b.Build()
|
||||
assert.NotNil(t, err, "build error")
|
||||
assert.Equal(t, err.Error(), "build failed with exit status 2\n"+
|
||||
"# _"+absPathBuild+"\n"+
|
||||
"# github.com/maxcnunes/gaper/testdata/build-failure\n"+
|
||||
"./main.go:4:6: func main must have no arguments and no return values\n"+
|
||||
"./main.go:5:1: missing return at end of function\n")
|
||||
"./main.go:5:1: missing return\n")
|
||||
}
|
||||
|
||||
func TestBuilderDefaultBinName(t *testing.T) {
|
||||
|
|
|
@ -4,14 +4,14 @@ import (
|
|||
"os"
|
||||
|
||||
"github.com/maxcnunes/gaper"
|
||||
"github.com/urfave/cli"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
// build info
|
||||
var (
|
||||
// keep the version hardcoded because on installing it through "go get/install"
|
||||
// it doesn't apply the build tags to override it. So, it is make easier for
|
||||
// people using in that case to find out which version they are using
|
||||
// Version is hardcoded because when installing it through "go get/install"
|
||||
// the build tags are not available to override it.
|
||||
// Update it after every release.
|
||||
version = "1.0.3-dev"
|
||||
)
|
||||
|
||||
|
@ -41,69 +41,61 @@ func main() {
|
|||
app.Usage = "Used to build and restart a Go project when it crashes or some watched file changes"
|
||||
app.Version = version
|
||||
|
||||
app.Action = func(c *cli.Context) {
|
||||
app.Action = func(c *cli.Context) error {
|
||||
args := parseArgs(c)
|
||||
chOSSiginal := make(chan os.Signal, 2)
|
||||
logger.Verbose(loggerVerbose)
|
||||
|
||||
if err := gaper.Run(args, chOSSiginal); err != nil {
|
||||
logger.Error(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
exts := make(cli.StringSlice, len(gaper.DefaultExtensions))
|
||||
for i := range gaper.DefaultExtensions {
|
||||
exts[i] = gaper.DefaultExtensions[i]
|
||||
return gaper.Run(args, chOSSiginal)
|
||||
}
|
||||
|
||||
// supported arguments
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "bin-name",
|
||||
Usage: "name for the binary built by gaper for the executed program (default current directory name)",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "build-path",
|
||||
Value: gaper.DefaultBuildPath,
|
||||
Usage: "path to the program source code",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "build-args",
|
||||
Usage: "arguments used on building the program",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "program-args",
|
||||
Usage: "arguments used on executing the program",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "verbose",
|
||||
Usage: "turns on the verbose messages from gaper",
|
||||
},
|
||||
cli.BoolFlag{
|
||||
&cli.BoolFlag{
|
||||
Name: "disable-default-ignore",
|
||||
Usage: "turns off default ignore for hidden files and folders, \"*_test.go\" files, and vendor folder",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
&cli.StringSliceFlag{
|
||||
Name: "watch, w",
|
||||
Usage: "list of folders or files to watch for changes",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
&cli.StringSliceFlag{
|
||||
Name: "ignore, i",
|
||||
Usage: "list of folders or files to ignore for changes\n" +
|
||||
"\t\t(always ignores all hidden files and directories)",
|
||||
},
|
||||
cli.IntFlag{
|
||||
&cli.IntFlag{
|
||||
Name: "poll-interval, p",
|
||||
Value: gaper.DefaultPoolInterval,
|
||||
Usage: "how often in milliseconds to poll watched files for changes",
|
||||
},
|
||||
cli.StringSliceFlag{
|
||||
&cli.StringSliceFlag{
|
||||
Name: "extensions, e",
|
||||
Value: &exts,
|
||||
Value: cli.NewStringSlice(gaper.DefaultExtensions...),
|
||||
Usage: "a comma-delimited list of file extensions to watch for changes",
|
||||
},
|
||||
cli.StringFlag{
|
||||
&cli.StringFlag{
|
||||
Name: "no-restart-on, n",
|
||||
Usage: "don't automatically restart the supervised program if it ends:\n" +
|
||||
"\t\tif \"error\", an exit code of 0 will still restart.\n" +
|
||||
|
|
10
gaper.go
10
gaper.go
|
@ -7,6 +7,7 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
|
@ -59,6 +60,8 @@ func Run(cfg *Config, chOSSiginal chan os.Signal) error {
|
|||
return err
|
||||
}
|
||||
|
||||
logger.Debugf("Config: %+v", cfg)
|
||||
|
||||
wCfg := WatcherConfig{
|
||||
DefaultIgnore: !cfg.DisableDefaultIgnore,
|
||||
PollInterval: cfg.PollInterval,
|
||||
|
@ -206,6 +209,13 @@ func setupConfig(cfg *Config) error {
|
|||
cfg.WatchItems = append(cfg.WatchItems, cfg.BuildPath)
|
||||
}
|
||||
|
||||
var extensions []string
|
||||
for i := range cfg.Extensions {
|
||||
values := strings.Split(cfg.Extensions[i], ",")
|
||||
extensions = append(extensions, values...)
|
||||
}
|
||||
cfg.Extensions = extensions
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
module github.com/maxcnunes/gaper
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/fatih/color v1.7.0
|
||||
github.com/mattn/go-colorable v0.0.9 // indirect
|
||||
github.com/mattn/go-isatty v0.0.3 // indirect
|
||||
github.com/mattn/go-shellwords v1.0.3
|
||||
github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3
|
||||
github.com/stretchr/objx v0.1.1 // indirect
|
||||
github.com/stretchr/testify v1.4.0
|
||||
github.com/urfave/cli/v2 v2.11.1
|
||||
golang.org/x/sys v0.0.0-20180616030259-6c888cc515d3 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
|
@ -0,0 +1,38 @@
|
|||
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 h1:p1EgwI/C7NhT0JmVkwCD2ZBK8j4aeHQX2pMHHBfMQ6w=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
|
||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-shellwords v1.0.3 h1:K/VxK7SZ+cvuPgFSLKi5QPI9Vr/ipOf4C1gN+ntueUk=
|
||||
github.com/mattn/go-shellwords v1.0.3/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
|
||||
github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3 h1:GWnsQiFbiQ7lREZbKkiJC6xxbymvny8GKtpdkPxjB6o=
|
||||
github.com/mattn/go-zglob v0.0.0-20180607075734-49693fbb3fe3/go.mod h1:9fxibJccNxU2cnpIKLRRFA7zX7qhkJIQWBb449FYHOo=
|
||||
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/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/urfave/cli/v2 v2.11.1 h1:UKK6SP7fV3eKOefbS87iT9YHefv7iB/53ih6e+GNAsE=
|
||||
github.com/urfave/cli/v2 v2.11.1/go.mod h1:f8iq5LtQ/bLxafbdBSLPPNsgaW0l/2fYYEHhAyPlwvo=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
|
||||
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
|
||||
golang.org/x/sys v0.0.0-20180616030259-6c888cc515d3 h1:FCfAlbS73+IQQJktaKGHldMdL2bGDVpm+OrCEbVz1f4=
|
||||
golang.org/x/sys v0.0.0-20180616030259-6c888cc515d3/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
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.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
|
@ -0,0 +1 @@
|
|||
test
|
|
@ -7,6 +7,8 @@ import (
|
|||
"net/http"
|
||||
)
|
||||
|
||||
var Version string
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) // nolint gas
|
||||
|
@ -16,6 +18,6 @@ func main() {
|
|||
log.Fatal("Forced failure")
|
||||
})
|
||||
|
||||
log.Println("Starting server")
|
||||
log.Println("Starting server: Version", Version)
|
||||
log.Fatal(http.ListenAndServe(":8080", nil))
|
||||
}
|
||||
|
|
14
watcher.go
14
watcher.go
|
@ -118,6 +118,11 @@ func (w *watcher) scanChange(watchPath string) (string, error) {
|
|||
|
||||
err := filepath.Walk(watchPath, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
// Ignore attempt to acess go temporary unmask
|
||||
if strings.Contains(err.Error(), "-go-tmp-umask") {
|
||||
return filepath.SkipDir
|
||||
}
|
||||
|
||||
return fmt.Errorf("couldn't walk to path \"%s\": %v", path, err)
|
||||
}
|
||||
|
||||
|
@ -189,13 +194,14 @@ func resolvePaths(paths []string, extensions map[string]bool) (map[string]bool,
|
|||
}
|
||||
|
||||
for _, match := range matches {
|
||||
// don't care for extension filter right now for non glob paths
|
||||
// since they could be a directory
|
||||
if isGlob {
|
||||
if _, ok := extensions[filepath.Ext(match)]; !ok {
|
||||
// ignore existing files that don't match the allowed extensions
|
||||
if f, err := os.Stat(match); !os.IsNotExist(err) && !f.IsDir() {
|
||||
if ext := filepath.Ext(match); ext != "" {
|
||||
if _, ok := extensions[ext]; !ok {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if _, ok := result[match]; !ok {
|
||||
result[match] = true
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package gaper
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
@ -105,14 +104,19 @@ func TestWatcherWatchChange(t *testing.T) {
|
|||
time.Sleep(time.Millisecond * 500)
|
||||
|
||||
// update hidden files and dirs to check builtin hidden ignore is working
|
||||
os.Chtimes(hiddenfile1, time.Now(), time.Now())
|
||||
os.Chtimes(hiddenfile2, time.Now(), time.Now())
|
||||
err = os.Chtimes(hiddenfile1, time.Now(), time.Now())
|
||||
assert.Nil(t, err, "chtimes error")
|
||||
|
||||
err = os.Chtimes(hiddenfile2, time.Now(), time.Now())
|
||||
assert.Nil(t, err, "chtimes error")
|
||||
|
||||
// update testfile first to check ignore is working
|
||||
os.Chtimes(testfile, time.Now(), time.Now())
|
||||
err = os.Chtimes(testfile, time.Now(), time.Now())
|
||||
assert.Nil(t, err, "chtimes error")
|
||||
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
os.Chtimes(mainfile, time.Now(), time.Now())
|
||||
err = os.Chtimes(mainfile, time.Now(), time.Now())
|
||||
assert.Nil(t, err, "chtimes error")
|
||||
|
||||
select {
|
||||
case event := <-w.Events():
|
||||
|
@ -173,6 +177,11 @@ func TestWatcherIgnoreFile(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
// create vendor folder for testing
|
||||
if err := os.MkdirAll("vendor", os.ModePerm); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
srvdir := "."
|
||||
|
@ -198,12 +207,12 @@ func TestWatcherIgnoreFile(t *testing.T) {
|
|||
filePath := tc.file
|
||||
file, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
fileInfo, err := file.Stat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, tc.expectIgnore, wt.ignoreFile(filePath, fileInfo))
|
||||
|
|
Loading…
Reference in New Issue