From b1dc7c172f0a911ff57daafefcb1244163be7b94 Mon Sep 17 00:00:00 2001 From: Matthias Fasching Date: Thu, 5 May 2022 12:21:27 +0000 Subject: [PATCH 1/4] Remove github.com/karrick/godirwalk dependency --- go.mod | 6 ---- go.sum | 18 ++++-------- plugins/plugdeps/plugdeps.go | 28 +++++++++---------- plugins/plugins.go | 53 ++++++++++++++++++------------------ 4 files changed, 45 insertions(+), 60 deletions(-) diff --git a/go.mod b/go.mod index b0703b5d5..fd6bcd759 100644 --- a/go.mod +++ b/go.mod @@ -18,23 +18,17 @@ require ( github.com/gobuffalo/plush/v4 v4.1.11 github.com/gobuffalo/pop/v6 v6.0.2 github.com/gobuffalo/tags/v3 v3.1.2 - github.com/google/go-cmp v0.5.6 // indirect github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 github.com/gorilla/sessions v1.2.1 - github.com/karrick/godirwalk v1.16.1 github.com/markbates/grift v1.5.0 github.com/markbates/oncer v1.0.0 github.com/markbates/refresh v1.12.0 github.com/markbates/safe v1.0.1 - github.com/mattn/go-colorable v0.1.12 // indirect github.com/monoculum/formam v3.5.5+incompatible github.com/psanford/memfs v0.0.0-20210214183328-a001468d78ef github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.4.0 github.com/stretchr/testify v1.7.1 - golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect - golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect - golang.org/x/text v0.3.7 // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc ) diff --git a/go.sum b/go.sum index cea2e2e78..8b4ea15ab 100644 --- a/go.sum +++ b/go.sum @@ -194,9 +194,8 @@ github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= -github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/martian/v3 v3.0.0/go.mod h1:y5Zk1BBys9G+gd6Jrk0W3cC1+ELVxBWuIGO+w/tUAp0= @@ -313,8 +312,6 @@ github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/ github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk= github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= -github.com/karrick/godirwalk v1.16.1 h1:DynhcF+bztK8gooS0+NDJFrdNZjJ3gzVzC545UNA9iw= -github.com/karrick/godirwalk v1.16.1/go.mod h1:j4mkqPuvaLI8mp1DroR3P6ad7cyYd4c1qeJ3RV7ULlk= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= @@ -350,9 +347,8 @@ github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kN github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= +github.com/mattn/go-colorable v0.1.9 h1:sqDoxXbdeALODt0DAeJCVp38ps9ZogZEAXjus69YV3U= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40= -github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= @@ -485,9 +481,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201203163018-be400aefbc4c/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97 h1:/UOmuWzQfxxo9UtlXMwuQU8CMgg1eZXqTRwkSQJWKOI= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= -golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -641,10 +636,8 @@ golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e h1:WUoyKPm6nCo1BnNUvPGnFG3T5DUVem42yDJZZ4CNxMA= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E= -golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY= @@ -656,9 +649,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/plugins/plugdeps/plugdeps.go b/plugins/plugdeps/plugdeps.go index 6f5a755b5..b80e4f3a2 100644 --- a/plugins/plugdeps/plugdeps.go +++ b/plugins/plugdeps/plugdeps.go @@ -2,12 +2,12 @@ package plugdeps import ( "fmt" + "io/fs" "os" "path/filepath" "strings" "github.com/gobuffalo/meta" - "github.com/karrick/godirwalk" ) // ErrMissingConfig is if config/buffalo-plugins.toml file is not found. Use plugdeps#On(app) to test if plugdeps are being used @@ -50,21 +50,19 @@ func listLocal(app meta.App) (*Plugins, error) { if _, err := os.Stat(proot); err != nil { return plugs, nil } - err := godirwalk.Walk(proot, &godirwalk.Options{ - FollowSymbolicLinks: true, - Callback: func(path string, info *godirwalk.Dirent) error { - if info.IsDir() { - return nil - } - base := filepath.Base(path) - if strings.HasPrefix(base, "buffalo-") { - plugs.Add(Plugin{ - Binary: base, - Local: "." + strings.TrimPrefix(path, app.Root), - }) - } + err := filepath.WalkDir(proot, func(path string, d fs.DirEntry, err error) error { + if d.IsDir() { return nil - }, + } + if !strings.HasPrefix(d.Name(), "buffalo-") { + return nil + } + + plugs.Add(Plugin{ + Binary: d.Name(), + Local: "." + strings.TrimPrefix(path, app.Root), + }) + return nil }) if err != nil { return plugs, err diff --git a/plugins/plugins.go b/plugins/plugins.go index f69401534..14e2daa6a 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "errors" + "io/fs" "os" "os/exec" "path/filepath" @@ -14,7 +15,6 @@ import ( "github.com/gobuffalo/buffalo/plugins/plugdeps" "github.com/gobuffalo/envy" "github.com/gobuffalo/meta" - "github.com/karrick/godirwalk" "github.com/markbates/oncer" "github.com/sirupsen/logrus" ) @@ -100,32 +100,33 @@ func Available() (List, error) { continue } - err := godirwalk.Walk(p, &godirwalk.Options{ - FollowSymbolicLinks: true, - Callback: func(path string, info *godirwalk.Dirent) error { - if err != nil { - // May indicate a permissions problem with the path, skip it - return nil - } - if info.IsDir() { - return nil - } - base := filepath.Base(path) - if strings.HasPrefix(base, "buffalo-") && !strings.HasPrefix(base, "buffalo-plugins") { - ctx, cancel := context.WithTimeout(context.Background(), timeout()) - commands := askBin(ctx, path) - cancel() - for _, c := range commands { - bc := c.BuffaloCommand - if _, ok := list[bc]; !ok { - list[bc] = Commands{} - } - c.Binary = path - list[bc] = append(list[bc], c) - } - } + err := filepath.WalkDir(p, func(path string, d fs.DirEntry, err error) error { + if err != nil { + // May indicate a permissions problem with the path, skip it + return nil + } + if d.IsDir() { + return nil + } + if !strings.HasPrefix(d.Name(), "buffalo-") { return nil - }, + } + if strings.HasPrefix(d.Name(), "buffalo-plugins") { + return nil + } + + ctx, cancel := context.WithTimeout(context.Background(), timeout()) + commands := askBin(ctx, path) + cancel() + for _, c := range commands { + bc := c.BuffaloCommand + if _, ok := list[bc]; !ok { + list[bc] = Commands{} + } + c.Binary = path + list[bc] = append(list[bc], c) + } + return nil }) if err != nil { From 5febe004a2768bc23f91702d20ac86b3915f662a Mon Sep 17 00:00:00 2001 From: Matthias Fasching Date: Thu, 5 May 2022 12:42:33 +0000 Subject: [PATCH 2/4] Remove github.com/markbates/oncer --- go.mod | 2 -- go.sum | 3 --- options.go | 13 +------------ plugins.go | 6 ++++-- plugins/plugins.go | 9 ++++++--- 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/go.mod b/go.mod index fd6bcd759..80bae1fb3 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,6 @@ require ( github.com/gorilla/mux v1.8.0 github.com/gorilla/sessions v1.2.1 github.com/markbates/grift v1.5.0 - github.com/markbates/oncer v1.0.0 github.com/markbates/refresh v1.12.0 github.com/markbates/safe v1.0.1 github.com/monoculum/formam v3.5.5+incompatible @@ -30,5 +29,4 @@ require ( github.com/sirupsen/logrus v1.8.1 github.com/spf13/cobra v1.4.0 github.com/stretchr/testify v1.7.1 - gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc ) diff --git a/go.sum b/go.sum index 8b4ea15ab..818bb6104 100644 --- a/go.sum +++ b/go.sum @@ -338,7 +338,6 @@ github.com/luna-duclos/instrumentedsql v1.1.3/go.mod h1:9J1njvFds+zN7y85EDhN9XNQ github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60= github.com/markbates/grift v1.5.0 h1:CZyK0k+8BdhQMgbwzuKMysC12y4tf9H004jAs/FutX4= github.com/markbates/grift v1.5.0/go.mod h1:1ssFm5gSGmzTkhi3Wfh/nqlU74J73TlAjoDMttQbpfY= -github.com/markbates/oncer v1.0.0 h1:E83IaVAHygyndzPimgUYJjbshhDTALZyXxvk9FOlQRY= github.com/markbates/oncer v1.0.0/go.mod h1:Z59JA581E9GP6w96jai+TGqafHPW+cPfRxz2aSZ0mcI= github.com/markbates/refresh v1.12.0 h1:vTgVPX4p77v26auBJhlgaTQ/adWAYSIcVYJvM63Nbpo= github.com/markbates/refresh v1.12.0/go.mod h1:Vpwi1+q+2U1VxE7C0Ilj6r2/+TigRzQcLez6XM3bPLc= @@ -819,8 +818,6 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc h1:2gGKlE2+asNV9m7xrywl36YYNnBG5ZQ0r/BOOxqPpmk= -gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc/go.mod h1:m7x9LTH6d71AHyAX77c9yqWCCa3UKHcVEj9y7hAtKDk= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= diff --git a/options.go b/options.go index 880189914..ec3998b84 100644 --- a/options.go +++ b/options.go @@ -14,7 +14,6 @@ import ( "github.com/gobuffalo/pop/v6" "github.com/gobuffalo/pop/v6/logging" "github.com/gorilla/sessions" - "github.com/markbates/oncer" ) // Options are used to configure and define how your application should run. @@ -29,9 +28,7 @@ type Options struct { // Env is the "environment" in which the App is running. Default is "development". Env string `json:"env"` - // LogLevel defaults to "debug". Deprecated use LogLvl instead - LogLevel string `json:"log_level"` - // LogLevl defaults to logger.DebugLvl. + // LogLvl defaults to logger.DebugLvl. LogLvl logger.Level `json:"log_lvl"` // Logger to be used with the application. A default one is provided. Logger Logger `json:"-"` @@ -125,14 +122,6 @@ func optionsWithDefaults(opts Options) Options { } } - if len(opts.LogLevel) > 0 { - var err error - oncer.Deprecate(0, "github.com/gobuffalo/buffalo#Options.LogLevel", "Use github.com/gobuffalo/buffalo#Options.LogLvl instead.") - opts.LogLvl, err = logger.ParseLevel(opts.LogLevel) - if err != nil { - opts.LogLvl = logger.DebugLevel - } - } if opts.LogLvl == 0 { opts.LogLvl = logger.DebugLevel } diff --git a/plugins.go b/plugins.go index 5b9a97460..8c10ac22d 100644 --- a/plugins.go +++ b/plugins.go @@ -6,18 +6,20 @@ import ( "os" "os/exec" "strings" + "sync" "github.com/gobuffalo/buffalo/plugins" "github.com/gobuffalo/envy" "github.com/gobuffalo/events" - "github.com/markbates/oncer" "github.com/markbates/safe" ) +var loadPlugins sync.Once + // LoadPlugins will add listeners for any plugins that support "events" func LoadPlugins() error { var errResult error - oncer.Do("events.LoadPlugins", func() { + loadPlugins.Do(func() { // don't send plugins events during testing if envy.Get("GO_ENV", "development") == "test" { return diff --git a/plugins/plugins.go b/plugins/plugins.go index 14e2daa6a..4271d2c48 100644 --- a/plugins/plugins.go +++ b/plugins/plugins.go @@ -10,21 +10,24 @@ import ( "os/exec" "path/filepath" "strings" + "sync" "time" "github.com/gobuffalo/buffalo/plugins/plugdeps" "github.com/gobuffalo/envy" "github.com/gobuffalo/meta" - "github.com/markbates/oncer" "github.com/sirupsen/logrus" ) const timeoutEnv = "BUFFALO_PLUGIN_TIMEOUT" +var timeoutOnce sync.Once +var availableOnce sync.Once + var t = time.Second * 2 func timeout() time.Duration { - oncer.Do("plugins.timeout", func() { + timeoutOnce.Do(func() { rawTimeout, err := envy.MustGet(timeoutEnv) if err == nil { if parsed, err := time.ParseDuration(rawTimeout); err == nil { @@ -64,7 +67,7 @@ var _list List // process. func Available() (List, error) { var err error - oncer.Do("plugins.Available", func() { + availableOnce.Do(func() { defer func() { if err := saveCache(); err != nil { logrus.Error(err) From 12a0d308c92a9dfb5248377a508c2eb35fbad797 Mon Sep 17 00:00:00 2001 From: Matthias Fasching Date: Thu, 5 May 2022 12:44:12 +0000 Subject: [PATCH 3/4] Fix various issues that golint complains about --- default_context_test.go | 10 +++++----- home.go | 2 +- mail/internal/mail/mime.go | 3 --- mail/internal/mail/mime_go14.go | 25 ------------------------- plugins/log.go | 2 +- plugins/log_debug.go | 2 +- plugins/plugdeps/plugdeps.go | 8 ++++---- plugins/plugdeps/plugins.go | 2 +- server_test.go | 14 +++++++------- 9 files changed, 20 insertions(+), 48 deletions(-) delete mode 100644 mail/internal/mail/mime_go14.go diff --git a/default_context_test.go b/default_context_test.go index 203781641..bf8c56463 100644 --- a/default_context_test.go +++ b/default_context_test.go @@ -143,7 +143,7 @@ func Test_DefaultContext_GetSet(t *testing.T) { r.Equal("Mark", c.Value("name").(string)) } -func Test_DefaultContext_Set_Unconfigured(t *testing.T) { +func Test_DefaultContext_Set_not_configured(t *testing.T) { r := require.New(t) c := DefaultContext{} @@ -162,7 +162,7 @@ func Test_DefaultContext_Value(t *testing.T) { r.Equal("Mark", c.Value("name").(string)) } -func Test_DefaultContext_Value_Unconfigured(t *testing.T) { +func Test_DefaultContext_Value_not_configured(t *testing.T) { r := require.New(t) c := DefaultContext{} r.Nil(c.Value("name")) @@ -323,7 +323,7 @@ func Test_DefaultContext_Data(t *testing.T) { r.EqualValues(map[string]interface{}{}, c.Data()) } -func Test_DefaultContext_Data_Unconfigured(t *testing.T) { +func Test_DefaultContext_Data_not_configured(t *testing.T) { r := require.New(t) c := DefaultContext{} @@ -345,7 +345,7 @@ func Test_DefaultContext_String_EmptyData(t *testing.T) { r.EqualValues("", c.String()) } -func Test_DefaultContext_String_EmptyData_Unconfigured(t *testing.T) { +func Test_DefaultContext_String_EmptyData_not_configured(t *testing.T) { r := require.New(t) c := DefaultContext{} @@ -372,7 +372,7 @@ func Test_DefaultContext_MarshalJSON_EmptyData(t *testing.T) { r.EqualValues(`{}`, string(jb)) } -func Test_DefaultContext_MarshalJSON_EmptyData_Unconfigured(t *testing.T) { +func Test_DefaultContext_MarshalJSON_EmptyData_not_configured(t *testing.T) { r := require.New(t) c := DefaultContext{} diff --git a/home.go b/home.go index 79255e547..83c3d9043 100644 --- a/home.go +++ b/home.go @@ -14,7 +14,7 @@ import ( could be strage. */ -// Home is a container for Domains and Groups that independantly serves a +// Home is a container for Domains and Groups that independently serves a // group of pages with its own Middleware and ErrorHandlers. It is usually // a multi-homed server domain or group of paths under a certain prefix. // diff --git a/mail/internal/mail/mime.go b/mail/internal/mail/mime.go index 580ac2c3e..61e259402 100644 --- a/mail/internal/mail/mime.go +++ b/mail/internal/mail/mime.go @@ -1,6 +1,3 @@ -//go:build go1.5 -// +build go1.5 - package mail import ( diff --git a/mail/internal/mail/mime_go14.go b/mail/internal/mail/mime_go14.go deleted file mode 100644 index bdb605dcc..000000000 --- a/mail/internal/mail/mime_go14.go +++ /dev/null @@ -1,25 +0,0 @@ -// +build !go1.5 - -package mail - -import "gopkg.in/alexcesaro/quotedprintable.v3" - -var newQPWriter = quotedprintable.NewWriter - -type mimeEncoder struct { - quotedprintable.WordEncoder -} - -var ( - bEncoding = mimeEncoder{quotedprintable.BEncoding} - qEncoding = mimeEncoder{quotedprintable.QEncoding} - lastIndexByte = func(s string, c byte) int { - for i := len(s) - 1; i >= 0; i-- { - - if s[i] == c { - return i - } - } - return -1 - } -) diff --git a/plugins/log.go b/plugins/log.go index 8a8909763..1512e826f 100644 --- a/plugins/log.go +++ b/plugins/log.go @@ -1,4 +1,4 @@ -//+build !debug +// +build !debug package plugins diff --git a/plugins/log_debug.go b/plugins/log_debug.go index 8c6fcae03..97457c0b6 100644 --- a/plugins/log_debug.go +++ b/plugins/log_debug.go @@ -1,4 +1,4 @@ -//+build debug +// +build debug package plugins diff --git a/plugins/plugdeps/plugdeps.go b/plugins/plugdeps/plugdeps.go index b80e4f3a2..a3c59d44f 100644 --- a/plugins/plugdeps/plugdeps.go +++ b/plugins/plugdeps/plugdeps.go @@ -13,7 +13,7 @@ import ( // ErrMissingConfig is if config/buffalo-plugins.toml file is not found. Use plugdeps#On(app) to test if plugdeps are being used var ErrMissingConfig = fmt.Errorf("could not find a buffalo-plugins config file at %s", ConfigPath(meta.New("."))) -// List all of the plugins the application depeneds on. Will return ErrMissingConfig +// List all of the plugins the application depends on. Will return ErrMissingConfig // if the app is not using config/buffalo-plugins.toml to manage their plugins. // Use plugdeps#On(app) to test if plugdeps are being used. func List(app meta.App) (*Plugins, error) { @@ -46,11 +46,11 @@ func List(app meta.App) (*Plugins, error) { func listLocal(app meta.App) (*Plugins, error) { plugs := New() - proot := filepath.Join(app.Root, "plugins") - if _, err := os.Stat(proot); err != nil { + pRoot := filepath.Join(app.Root, "plugins") + if _, err := os.Stat(pRoot); err != nil { return plugs, nil } - err := filepath.WalkDir(proot, func(path string, d fs.DirEntry, err error) error { + err := filepath.WalkDir(pRoot, func(path string, d fs.DirEntry, err error) error { if d.IsDir() { return nil } diff --git a/plugins/plugdeps/plugins.go b/plugins/plugdeps/plugins.go index 4f3266051..3a9d9ab0d 100644 --- a/plugins/plugdeps/plugins.go +++ b/plugins/plugdeps/plugins.go @@ -32,7 +32,7 @@ func (plugs *Plugins) Decode(r io.Reader) error { tp := &tomlPlugins{ Plugins: []Plugin{}, } - if _, err := toml.DecodeReader(r, tp); err != nil { + if _, err := toml.NewDecoder(r).Decode(tp); err != nil { return err } for _, p := range tp.Plugins { diff --git a/server_test.go b/server_test.go index 1e8f148b9..9ff9b6384 100644 --- a/server_test.go +++ b/server_test.go @@ -16,9 +16,9 @@ import ( // timing sensitive. Adjust this timing values if they are failing due to // timing issue. const ( - WAIT_START = 2 - WAIT_RUN = 2 - CONSUMER_RUN = 8 + waitStart = 2 + waitRun = 2 + consumerRun = 8 ) // startApp starts given buffalo app and check its exit status. @@ -32,7 +32,7 @@ func startApp(app *App, wg *sync.WaitGroup, r *require.Assertions) { }() // wait until the server started. // could be improved with connection test but that's too much... - time.Sleep(WAIT_START * time.Second) + time.Sleep(waitStart * time.Second) } func Test_Server_Simple(t *testing.T) { @@ -55,7 +55,7 @@ var handlerDone = false // timeConsumer consumes about 10 minutes for processing its request func timeConsumer(c Context) error { - for i := 0; i < CONSUMER_RUN; i++ { + for i := 0; i < consumerRun; i++ { fmt.Println("#") time.Sleep(1 * time.Second) } @@ -89,7 +89,7 @@ func Test_Server_GracefulShutdownOngoingRequest(t *testing.T) { firstQuery = true }() // make sure the request sent - time.Sleep(WAIT_RUN * time.Second) + time.Sleep(waitRun * time.Second) app.cancel() time.Sleep(1 * time.Second) // make sure the server started shutdown. @@ -114,7 +114,7 @@ func Test_Server_GracefulShutdownOngoingRequest(t *testing.T) { var timerDone = false func timerWorker(args worker.Args) error { - for i := 0; i < CONSUMER_RUN; i++ { + for i := 0; i < consumerRun; i++ { fmt.Println("%") time.Sleep(1 * time.Second) } From 1ed9b9f2eeeb53c0e9e5f294d8def7d2cbe71eda Mon Sep 17 00:00:00 2001 From: Matthias Fasching Date: Sat, 14 May 2022 21:26:07 +0000 Subject: [PATCH 4/4] Remove dependency on safe --- go.mod | 1 - go.sum | 1 - plugins.go | 36 +++++++++++++++--------------------- worker/simple.go | 20 ++++++++++++++++++-- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 80bae1fb3..89a385060 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,6 @@ require ( github.com/gorilla/sessions v1.2.1 github.com/markbates/grift v1.5.0 github.com/markbates/refresh v1.12.0 - github.com/markbates/safe v1.0.1 github.com/monoculum/formam v3.5.5+incompatible github.com/psanford/memfs v0.0.0-20210214183328-a001468d78ef github.com/sirupsen/logrus v1.8.1 diff --git a/go.sum b/go.sum index 818bb6104..62f5b4eab 100644 --- a/go.sum +++ b/go.sum @@ -341,7 +341,6 @@ github.com/markbates/grift v1.5.0/go.mod h1:1ssFm5gSGmzTkhi3Wfh/nqlU74J73TlAjoDM github.com/markbates/oncer v1.0.0/go.mod h1:Z59JA581E9GP6w96jai+TGqafHPW+cPfRxz2aSZ0mcI= github.com/markbates/refresh v1.12.0 h1:vTgVPX4p77v26auBJhlgaTQ/adWAYSIcVYJvM63Nbpo= github.com/markbates/refresh v1.12.0/go.mod h1:Vpwi1+q+2U1VxE7C0Ilj6r2/+TigRzQcLez6XM3bPLc= -github.com/markbates/safe v1.0.1 h1:yjZkbvRM6IzKj9tlu/zMJLS0n/V351OZWRnF3QfaUxI= github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= diff --git a/plugins.go b/plugins.go index 8c10ac22d..e395c7433 100644 --- a/plugins.go +++ b/plugins.go @@ -11,7 +11,6 @@ import ( "github.com/gobuffalo/buffalo/plugins" "github.com/gobuffalo/envy" "github.com/gobuffalo/events" - "github.com/markbates/safe" ) var loadPlugins sync.Once @@ -35,28 +34,23 @@ func LoadPlugins() error { continue } err := func(c plugins.Command) error { - return safe.RunE(func() error { - n := fmt.Sprintf("[PLUGIN] %s %s", c.Binary, c.Name) - fn := func(e events.Event) { - b, err := json.Marshal(e) - if err != nil { - fmt.Println("error trying to marshal event", e, err) - return - } - cmd := exec.Command(c.Binary, c.UseCommand, string(b)) - cmd.Stderr = os.Stderr - cmd.Stdout = os.Stdout - cmd.Stdin = os.Stdin - if err := cmd.Run(); err != nil { - fmt.Println("error trying to send event", strings.Join(cmd.Args, " "), err) - } - } - _, err := events.NamedListen(n, events.Filter(c.ListenFor, fn)) + n := fmt.Sprintf("[PLUGIN] %s %s", c.Binary, c.Name) + fn := func(e events.Event) { + b, err := json.Marshal(e) if err != nil { - return err + fmt.Println("error trying to marshal event", e, err) + return + } + cmd := exec.Command(c.Binary, c.UseCommand, string(b)) + cmd.Stderr = os.Stderr + cmd.Stdout = os.Stdout + cmd.Stdin = os.Stdin + if err := cmd.Run(); err != nil { + fmt.Println("error trying to send event", strings.Join(cmd.Args, " "), err) } - return nil - }) + } + _, err := events.NamedListen(n, events.Filter(c.ListenFor, fn)) + return err }(c) if err != nil { errResult = err diff --git a/worker/simple.go b/worker/simple.go index 6097cbb3a..55227342e 100644 --- a/worker/simple.go +++ b/worker/simple.go @@ -2,11 +2,11 @@ package worker import ( "context" + "errors" "fmt" "sync" "time" - "github.com/markbates/safe" "github.com/sirupsen/logrus" ) @@ -122,7 +122,7 @@ func (w *Simple) Perform(job Job) error { w.wg.Add(1) go func() { defer w.wg.Done() - err := safe.RunE(func() error { + err := safeRun(func() error { return h(job.Args) }) @@ -139,6 +139,22 @@ func (w *Simple) Perform(job Job) error { return err } +// safeRun the function safely knowing that if it panics +// the panic will be caught and returned as an error +func safeRun(fn func() error) (err error) { + defer func() { + if ex := recover(); ex != nil { + if e, ok := ex.(error); ok { + err = e + return + } + err = errors.New(fmt.Sprint(ex)) + } + }() + + return fn() +} + // PerformAt performs a job at a particular time using a goroutine. func (w *Simple) PerformAt(job Job, t time.Time) error { return w.PerformIn(job, time.Until(t))