Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when using grpc and g.client(httpclient) together, the http client returns error service not found with name "127.0.0.1:8001" #3292

Closed
rubyangxg opened this issue Jan 31, 2024 · 0 comments
Assignees
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.

Comments

@rubyangxg
Copy link

rubyangxg commented Jan 31, 2024

What version of Go and system type/arch are you using?

Env Detail:
Go Version: go1.21.5 darwin/amd64
GF Version(go.mod): cannot find go.mod

What version of GoFrame are you using?

v2.6.2

Can this bug be re-produced with the latest release?
yes

What did you do?

package main

import (
	"context"
	"fmt"
	"github.com/gogf/gf/v2/encoding/gjson"
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
)

func Login(ctx context.Context, username string, password string) string {
	url := "http://127.0.0.1:8001/controller/users/login"
	r, err := g.Client().Header(map[string]string{
		"Content-Type": "application/json",
	}).Post(
		ctx,
		url,
		fmt.Sprintf(`{"userName":"%s","password":"%s"}`, username, password),
	)
	if err != nil {
		panic(err)
	}
	defer r.Close()
	j, err := gjson.LoadContent(r.ReadAllString())
	if err != nil {
		return ""
	}
	var token = ""
	code := j.Get("code").Int()
	if code == 0 {
		token = j.GetJson("data").Get("token").String()
	}
	return token
}

func main() {
	s := g.Server()
	s.BindHandler("POST:/controller/users/login", func(r *ghttp.Request) {
		r.Response.WriteJson(r.Router)
	})
	s.SetPort(8001)
	s.Run()
}

package main

import (
	"fmt"
	"github.com/gogf/gf/contrib/rpc/grpcx/v2"
	"github.com/gogf/gf/v2/os/gctx"
	"github.com/gogf/gf/v2/test/gtest"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials/insecure"
	"testing"
)

func Test_Create(t *testing.T) {
	gtest.C(t, func(t *gtest.T) {
		var (
			ctx = gctx.GetInitCtx()
		)
		var (
			conn = grpcx.Client.MustNewGrpcClientConn("127.0.0.1:8888",
				grpc.WithTransportCredentials(insecure.NewCredentials()))
		)
		println(conn)
		token := Login(ctx, "aaa", "bbb")
		fmt.Println(token)
	})
}

What did you expect to see?
pass

What did you see instead?

@rubyangxg rubyangxg added the bug It is confirmed a bug, but don't worry, we'll handle it. label Jan 31, 2024
@gqcn gqcn added the wip label Jan 31, 2024
@gqcn gqcn self-assigned this Jan 31, 2024
@gqcn gqcn changed the title grpc和g.client(httpclient)混用时,提示service not found with name "127.0.0.1:8001" when using grpc and g.client(httpclient) together, the http client returns error service not found with name "127.0.0.1:8001" Jan 31, 2024
gqcn added a commit that referenced this issue Jan 31, 2024
@gqcn gqcn added done This issue is done, which may be release in next version. and removed wip labels Jan 31, 2024
@gqcn gqcn closed this as completed Jan 31, 2024
gqcn added a commit that referenced this issue Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it. done This issue is done, which may be release in next version.
Projects
None yet
Development

No branches or pull requests

2 participants