diff --git a/.golangci.yaml b/.golangci.yaml index 9182c21..6e7fd66 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -118,6 +118,8 @@ linters: #- wsl # add or remove empty lines [fast: true, auto-fix: false] #- zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg` [fast: false, auto-fix: false] settings: + gomoddirectives: + replace-local: true gocritic: disabled-checks: - ifElseChain diff --git a/Makefile b/Makefile index 6cb72ff..2bb53e6 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ endif .husky: @git config core.hooksPath .husky -## === Tasks === +### Tasks .PHONY: check ## Run lint & test @@ -38,22 +38,22 @@ check: tidy examples lint test .PHONY: tidy ## Run go mod tidy tidy: - @go mod tidy + @find . -name go.mod -execdir go mod tidy \; .PHONY: lint ## Run linter lint: - @golangci-lint run + @find . -name go.mod -execdir golangci-lint run \; .PHONY: lint.fix ## Run linter and fix lint.fix: - @golangci-lint run --fix + @find . -name go.mod -execdir golangci-lint run --fix \; .PHONY: test ## Run go test test: - @GO_TEST_TAGS=-skip go test -coverprofile=coverage.out --tags=safe -race ./... + @GO_TEST_TAGS=-skip find . -name go.mod -execdir go test -coverprofile=coverage.out --tags=safe -race ./... \; .PHONY: build ## Build binary @@ -77,13 +77,6 @@ install: install.debug: @go install -gcflags "all=-N -l" cmd/gotsrpc/gotsrpc.go -.PHONY: outdated -## Show outdated direct dependencies -outdated: - @go list -u -m -json all | go-mod-outdated -update -direct - -## === Tools === - EXAMPLES=basic errors monitor nullable union time types define examples .PHONY: example.$(1) @@ -105,10 +98,8 @@ example.$(1).lint: endef $(foreach p,$(EXAMPLES),$(eval $(call examples,$(p)))) -## === Examples === - .PHONY: examples -## Build examples +## Generate examples examples: @for name in example/*/; do\ if [ $$name != "example/node_modules/" ]; then \ @@ -118,36 +109,23 @@ examples: done .PHONY: examples -## === Utils === +### Utils +.PHONY: help ## Show help text help: + @echo "gotsrpc\n" + @echo "Usage:\n make [task]" @awk '{ \ - if ($$0 ~ /^.PHONY: [a-zA-Z\-\_0-9]+$$/) { \ - helpCommand = substr($$0, index($$0, ":") + 2); \ - if (helpMessage) { \ - printf "\033[36m%-23s\033[0m %s\n", \ - helpCommand, helpMessage; \ - helpMessage = ""; \ - } \ - } else if ($$0 ~ /^[a-zA-Z\-\_0-9.]+:/) { \ - helpCommand = substr($$0, 0, index($$0, ":")); \ - if (helpMessage) { \ - printf "\033[36m%-23s\033[0m %s\n", \ - helpCommand, helpMessage"\n"; \ - helpMessage = ""; \ - } \ - } else if ($$0 ~ /^##/) { \ - if (helpMessage) { \ - helpMessage = helpMessage"\n "substr($$0, 3); \ - } else { \ - helpMessage = substr($$0, 3); \ - } \ - } else { \ - if (helpMessage) { \ - print "\n "helpMessage"\n" \ - } \ - helpMessage = ""; \ - } \ - }' \ - $(MAKEFILE_LIST) + if($$0 ~ /^### /){ \ + if(help) printf "%-23s %s\n\n", cmd, help; help=""; \ + printf "\n%s:\n", substr($$0,5); \ + } else if($$0 ~ /^[a-zA-Z0-9._-]+:/){ \ + cmd = substr($$0, 1, index($$0, ":")-1); \ + if(help) printf " %-23s %s\n", cmd, help; help=""; \ + } else if($$0 ~ /^##/){ \ + help = help ? help "\n " substr($$0,3) : substr($$0,3); \ + } else if(help){ \ + print "\n " help "\n"; help=""; \ + } \ + }' $(MAKEFILE_LIST) diff --git a/example/basic/main.go b/example/basic/main.go index c70a230..8f28df1 100644 --- a/example/basic/main.go +++ b/example/basic/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "net/http" "os/exec" "strings" @@ -10,6 +11,7 @@ import ( ) func main() { + ctx := context.Background() fs := http.FileServer(http.Dir("./client")) ws := service.NewDefaultServiceGoTSRPCProxy(&service.Handler{}) @@ -25,7 +27,7 @@ func main() { go func() { time.Sleep(time.Second) - _ = exec.Command("open", "http://127.0.0.1:3000").Run() + _ = exec.CommandContext(ctx, "open", "http://127.0.0.1:3000").Run() }() panic(http.ListenAndServe("localhost:3000", mux)) //nolint:gosec diff --git a/example/errors/main.go b/example/errors/main.go index 3f8174b..a0df151 100644 --- a/example/errors/main.go +++ b/example/errors/main.go @@ -22,6 +22,7 @@ import ( ) func main() { + ctx := context.Background() fs := http.FileServer(http.Dir("./client")) fh := frontendsvs.NewDefaultServiceGoTSRPCProxy(frontend.New(backendsvs.NewDefaultServiceGoTSRPCClient("http://localhost:3000"))) bh := backendsvs.NewDefaultServiceGoTSRPCProxy(backend.New()) @@ -40,7 +41,7 @@ func main() { go func() { time.Sleep(time.Second) - _ = exec.Command("open", "http://127.0.0.1:3000").Run() + _ = exec.CommandContext(ctx, "open", "http://127.0.0.1:3000").Run() call() }() diff --git a/example/go.sum b/example/go.sum index a261063..4145144 100644 --- a/example/go.sum +++ b/example/go.sum @@ -1,9 +1,19 @@ +github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= +github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg= +github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs= +github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/foomo/go v0.0.3 h1:5pGzcPC78dImuBTT7nsZZnH+GIQUylbCtMkFEH26uZk= +github.com/foomo/go v0.0.3/go.mod h1:x6g64wiQusqaFElnh5rlk9unCgLKmfUWy0YFLejJxio= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0= github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= +github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E= +github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -16,6 +26,8 @@ github.com/ugorji/go/codec v1.3.1-0.20250729181524-a9af3d3cd758 h1:coa7c9qOU6bkV github.com/ugorji/go/codec v1.3.1-0.20250729181524-a9af3d3cd758/go.mod h1:pRBVtBSKl77K30Bv8R2P+cLSGaTtex6fsA2Wjqmfxj4= github.com/valyala/gorpc v0.0.0-20160519171614-908281bef774 h1:SUHFQHAaySqF0YHCmmm0EIFooFZpDPpi5KTom7YJ07c= github.com/valyala/gorpc v0.0.0-20160519171614-908281bef774/go.mod h1:8uNqM1i7pr0jO7gdvbNCgsSa8Ki2vMh7JCQxO9BlF90= +github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc= +github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw= golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U= golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI= golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug= diff --git a/example/monitor/main.go b/example/monitor/main.go index 97bf63f..aa3b0c2 100644 --- a/example/monitor/main.go +++ b/example/monitor/main.go @@ -26,6 +26,7 @@ func init() { } func main() { + ctx := context.Background() fs := http.FileServer(http.Dir("./client")) ws := service.NewDefaultServiceGoTSRPCProxy(&service.Handler{}) @@ -41,7 +42,7 @@ func main() { go func() { time.Sleep(time.Second) - _ = exec.Command("open", "http://127.0.0.1:3000").Run() + _ = exec.CommandContext(ctx, "open", "http://127.0.0.1:3000").Run() call() }() diff --git a/example/nullable/main.go b/example/nullable/main.go index b17ac62..11bd78c 100644 --- a/example/nullable/main.go +++ b/example/nullable/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "net/http" "os/exec" "strings" @@ -10,6 +11,7 @@ import ( ) func main() { + ctx := context.Background() fs := http.FileServer(http.Dir("./client")) ws := service.NewDefaultServiceGoTSRPCProxy(&service.Handler{}) @@ -25,7 +27,7 @@ func main() { go func() { time.Sleep(time.Second) - _ = exec.Command("open", "http://127.0.0.1:3000").Run() + _ = exec.CommandContext(ctx, "open", "http://127.0.0.1:3000").Run() }() panic(http.ListenAndServe("localhost:3000", mux)) //nolint:gosec diff --git a/example/time/main.go b/example/time/main.go index 731ff97..b607b50 100644 --- a/example/time/main.go +++ b/example/time/main.go @@ -14,6 +14,7 @@ import ( ) func main() { + ctx := context.Background() fs := http.FileServer(http.Dir("./client")) ws := service.NewDefaultServiceGoTSRPCProxy(&service.Handler{}) @@ -29,7 +30,7 @@ func main() { go func() { time.Sleep(time.Second) - _ = exec.Command("open", "http://127.0.0.1:3000").Run() + _ = exec.CommandContext(ctx, "open", "http://127.0.0.1:3000").Run() call() }() diff --git a/example/union/main.go b/example/union/main.go index d13b336..d94f212 100644 --- a/example/union/main.go +++ b/example/union/main.go @@ -8,11 +8,11 @@ import ( "time" "github.com/davecgh/go-spew/spew" - "github.com/foomo/gotsrpc/v2/example/union/service" ) func main() { + ctx := context.Background() fs := http.FileServer(http.Dir("./client")) ws := service.NewDefaultServiceGoTSRPCProxy(&service.Handler{}) @@ -28,7 +28,7 @@ func main() { go func() { time.Sleep(time.Second) - _ = exec.Command("open", "http://127.0.0.1:3000").Run() + _ = exec.CommandContext(ctx, "open", "http://127.0.0.1:3000").Run() call() }()