improve service registry for package ghttp/gclient

This commit is contained in:
John Guo
2022-01-27 18:12:39 +08:00
parent 3cb578488c
commit 3a658cdb85
26 changed files with 228 additions and 64 deletions

View File

@ -4,8 +4,8 @@ go 1.15
require (
github.com/gogf/gf/contrib/registry/etcd/v2 v2.0.0-rc2
github.com/gogf/gf/contrib/resolver/v2 v2.0.0-rc2
github.com/gogf/gf/contrib/balancer/v2 v2.0.0-rc2
github.com/gogf/gf/contrib/grpc/resolver/v2 v2.0.0-rc2
github.com/gogf/gf/contrib/grpc/balancer/v2 v2.0.0-rc2
github.com/gogf/gf/v2 v2.0.0-rc2
github.com/golang/protobuf v1.5.2
google.golang.org/grpc v1.43.0
@ -13,8 +13,8 @@ require (
)
replace (
github.com/gogf/gf/contrib/balancer/v2 => ../contrib/balancer/
github.com/gogf/gf/contrib/registry/etcd/v2 => ../contrib/registry/etcd/
github.com/gogf/gf/contrib/resolver/v2 => ../contrib/resolver/
github.com/gogf/gf/contrib/registry/etcd/v2 => ../contrib/registry/etcd/
github.com/gogf/gf/contrib/grpc/balancer/v2 => ../contrib/grpc/balancer/
github.com/gogf/gf/contrib/grpc/resolver/v2 => ../contrib/grpc/resolver/
github.com/gogf/gf/v2 => ../
)

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"time"
"github.com/gogf/gf/contrib/registry/etcd/v2"
"github.com/gogf/gf/v2/frame/g"
@ -12,10 +13,13 @@ import (
func main() {
gsvc.SetRegistry(etcd.New(`127.0.0.1:2379`))
res, err := g.Client().Get(gctx.New(), `http://hello.svc:12345/`)
if err != nil {
panic(err)
for i := 0; i < 100; i++ {
res, err := g.Client().Get(gctx.New(), `http://hello.svc/`)
if err != nil {
panic(err)
}
fmt.Println(res.ReadAllString())
res.Close()
time.Sleep(time.Second)
}
defer res.Close()
fmt.Println(res.ReadAllString())
}

View File

@ -12,6 +12,7 @@ func main() {
s := g.Server(`hello.svc`)
s.BindHandler("/", func(r *ghttp.Request) {
g.Log().Info(r.Context(), `request received`)
r.Response.Write(`Hello world`)
})
s.Run()