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
41 changes: 41 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Go

on:
pull_request:
branches:
- main
- master
- release/v*
- test-workflow-main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.22.12"

- name: Lint with golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: v2.5.0
only-new-issues: true

test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: "1.22.12"

- name: Run go test
run: go test -v ./...
101 changes: 101 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# https://golangci-lint.run/docs/configuration/file/
version: "2"

run:
timeout: 5m

issues:
new: true
whole-files: true
new-from-rev: HEAD~
max-same-issues: 50

severity:
default: error
# rules:
# - linters:
# - dupl
# severity: error

formatters:
enable:
- gci
- gofmt
- gofumpt
- goimports
- golines
- swaggo
settings:
gofmt:
rewrite-rules:
- pattern: "interface{}"
replacement: "any"
gofumpt:
extra-rules: true
exclusions:
paths: []

linters:
default: none
enable:
# Standard
- errcheck
- govet
- ineffassign
- staticcheck
- unused

# Additional
- bodyclose
- depguard
- errname
- errorlint
- gocognit
- goconst
- goheader
- gomodguard
- goprintffuncname
- gosec
- nakedret
- nilerr
- nilnil
- noctx
- nolintlint
- prealloc
- promlinter
- revive
- testifylint
- testpackage
- thelper
- usestdlibvars
- wastedassign
- wsl_v5

disable: []

settings:
depguard:
rules:
main:
deny:
- pkg: github.com/pkg/errors
desc: Should be replaced by standard lib errors package
- pkg: golang.org/x/exp/slices
desc: Should be replaced by standard lib slices package
- pkg: github.com/go-resty/resty$
desc: Use github.com/go-resty/resty/v2 instead
- pkg: github.com/aws/smithy-go/ptr$
desc: Use github.com/aws/aws-sdk-go-v2/aws instead
govet:
enable:
- nilness

# exclusions:
# paths:
# - (.+)_test\.go
# rules:
# - path: (.+)_test\.go
# linters:
# - dupl
# - mnd
# - lll
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
golang 1.22.7
golangci-lint 1.60.3
golang 1.22.12
golangci-lint 2.5.0
26 changes: 15 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
MODULE_DIRS = . ./tools
MODULE_DIRS = .

gowork:
go work init . ./tools
go work init .

tidy:
$(foreach dir,$(MODULE_DIRS), \
(cd $(dir) && go mod tidy) &&) true
go mod tidy

install: tidy
cd tools && go install \
mvdan.cc/gofumpt
install-asdf:
asdf install

install: install-asdf tidy
# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v2.5.0

fmt: install
gofumpt -l -w -extra .
golangci-lint fmt -v ./...

fix: install
golangci-lint run -v --fix ./...

lint: install
golangci-lint run ./...
golangci-lint run -v ./...

test:
test: install
go test ./...

check: fmt lint test
check: fix lint test
7 changes: 6 additions & 1 deletion errgroup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Package errgroup provides a more robust error group implementation
// that extends golang.org/x/sync/errgroup with panic recovery.
package errgroup

import (
"context"
"errors"

"golang.org/x/sync/errgroup"
)
Expand Down Expand Up @@ -61,7 +64,9 @@ func (g *Group) TryGo(f func() error) bool {
// returns the first non-nil error (if any) from them.
func (g *Group) Wait() error {
err := g.g.Wait()
if p, ok := err.(panicked); ok {

var p panicked
if errors.As(err, &p) {
// re-panic to keep the original stack trace
panic(p.panic)
}
Expand Down
11 changes: 6 additions & 5 deletions errgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/min0625/errgroup"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func Test_Group(t *testing.T) {
Expand All @@ -32,9 +33,9 @@ func Test_Group(t *testing.T) {
return nil
})

assert.NoError(t, g.Wait())
assert.Equal(t, jobXIsDone, true)
assert.Equal(t, jobYIsDone, true)
require.NoError(t, g.Wait())
assert.True(t, jobXIsDone)
assert.True(t, jobYIsDone)
}

func Test_WithContext(t *testing.T) {
Expand All @@ -61,8 +62,8 @@ func Test_WithContext(t *testing.T) {
return nil
})

assert.ErrorIs(t, g.Wait(), myErr)
assert.Equal(t, jobIsCanceled, true)
require.ErrorIs(t, g.Wait(), myErr)
assert.True(t, jobIsCanceled, true)
}

func Test_Group_Error(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func Example() {

if err := g.Wait(); err != nil {
// Handle error
fmt.Println(err)
return
}

// Output: oops
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/min0625/errgroup

go 1.22.7
go 1.22.12

require (
github.com/stretchr/testify v1.9.0
Expand Down
12 changes: 0 additions & 12 deletions tools/go.mod

This file was deleted.

20 changes: 0 additions & 20 deletions tools/go.sum

This file was deleted.

8 changes: 0 additions & 8 deletions tools/tools.go

This file was deleted.