revert: debug

This commit is contained in:
Kevin Franklin Kim 2025-03-07 15:16:36 +01:00
parent 07c3475cc9
commit 164ebf3a66
No known key found for this signature in database
3 changed files with 16 additions and 36 deletions

View File

@ -1,30 +1,34 @@
.DEFAULT_GOAL:=help .DEFAULT_GOAL:=help
.PHONY: check
## Run lint & test
check: tidy examples lint test
.PHONY: test .PHONY: test
## Run go test ## Run go test
test: test:
go test -v ./... @go test -v ./...
.PHONY: install .PHONY: install
## Run go install ## Run go install
install: install:
go install cmd/gotsrpc/gotsrpc.go @go install cmd/gotsrpc/gotsrpc.go
.PHONY: install.debug .PHONY: install.debug
## Run go install with debug ## Run go install with debug
install.debug: install.debug:
go install -gcflags "all=-N -l" cmd/gotsrpc/gotsrpc.go @go install -gcflags "all=-N -l" cmd/gotsrpc/gotsrpc.go
.PHONY: outdated .PHONY: outdated
## Show outdated direct dependencies ## Show outdated direct dependencies
outdated: outdated:
go list -u -m -json all | go-mod-outdated -update -direct @go list -u -m -json all | go-mod-outdated -update -direct
.PHONY: build.debug .PHONY: build.debug
## Build binary in debug mode ## Build binary in debug mode
build.debug: build.debug:
rm -f bin/gotsrpc @rm -f bin/gotsrpc
go build -gcflags "all=-N -l" -o bin/gotsrpc cmd/gotsrpc/gotsrpc.go @go build -gcflags "all=-N -l" -o bin/gotsrpc cmd/gotsrpc/gotsrpc.go
## === Tools === ## === Tools ===
@ -49,17 +53,18 @@ example.$(1).lint:
endef endef
$(foreach p,$(EXAMPLES),$(eval $(call examples,$(p)))) $(foreach p,$(EXAMPLES),$(eval $(call examples,$(p))))
## Run go mod tidy recursive
.PHONY: lint .PHONY: lint
## Run linter
lint: lint:
@golangci-lint run @golangci-lint run
.PHONY: lint.fix .PHONY: lint.fix
## Run linter and fix
lint.fix: lint.fix:
@golangci-lint run --fix @golangci-lint run --fix
.PHONY: tidy .PHONY: tidy
## Run go mod tidy recursive ## Run go mod tidy
tidy: tidy:
@go mod tidy @go mod tidy

View File

@ -1,9 +1,7 @@
package frontend package frontend
import ( import (
"fmt"
"net/http" "net/http"
"time"
"github.com/foomo/gotsrpc/v2/example/errors/service/backend" "github.com/foomo/gotsrpc/v2/example/errors/service/backend"
"github.com/foomo/gotsrpc/v2/example/errors/service/frontend" "github.com/foomo/gotsrpc/v2/example/errors/service/frontend"
@ -20,12 +18,6 @@ func New(client backend.ServiceGoTSRPCClient) *Handler {
} }
func (h *Handler) Simple(w http.ResponseWriter, r *http.Request) (e *frontend.ErrSimple) { func (h *Handler) Simple(w http.ResponseWriter, r *http.Request) (e *frontend.ErrSimple) {
fmt.Println("==========> incoming")
time.Sleep(time.Second)
if r.Context().Err() != nil {
fmt.Println("==========>" + r.Context().Err().Error())
}
fmt.Println("<========== outgoing")
return return
} }

View File

@ -8,6 +8,7 @@ import (
"context" "context"
"fmt" "fmt"
"net/http" "net/http"
"os/exec"
"strings" "strings"
"time" "time"
@ -39,7 +40,7 @@ func main() {
go func() { go func() {
time.Sleep(time.Second) time.Sleep(time.Second)
// _ = exec.Command("open", "http://127.0.0.1:3000").Run() _ = exec.Command("open", "http://127.0.0.1:3000").Run()
call() call()
}() }()
@ -48,30 +49,12 @@ func main() {
func call() { func call() {
ctx := context.Background() ctx := context.Background()
time.Sleep(time.Second)
ctx2, cancel := context.WithCancel(ctx)
req, _ := http.NewRequestWithContext(ctx2, "POST", "http://127.0.0.1:3000/service/frontend/Simple", nil)
go func() {
time.Sleep(time.Millisecond * 100)
fmt.Println("cancel")
cancel()
}()
fmt.Println("sending request")
res, err := http.DefaultClient.Do(req)
time.Sleep(time.Second)
fmt.Printf("%v\n", err)
fmt.Printf("%v\n", res.StatusCode)
c := backendsvs.NewDefaultServiceGoTSRPCClient("http://localhost:3000") c := backendsvs.NewDefaultServiceGoTSRPCClient("http://localhost:3000")
{ {
fmt.Println("--- Error ----------------------") fmt.Println("--- Error ----------------------")
var gotsrpcErr *gotsrpc.Error var gotsrpcErr *gotsrpc.Error
serviceErr, err := c.Error(ctx)
ctx2, cancel2 := context.WithCancel(ctx)
cancel2()
serviceErr, err := c.Error(ctx2)
if err != nil { if err != nil {
panic("client error should be nil") panic("client error should be nil")
} else if serviceErr == nil { } else if serviceErr == nil {