examples: fix dir structure (#768)

* fix dir structure
pull/772/head
Tony Chen 4 years ago committed by GitHub
parent 74272546ca
commit 5a8acec808
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      examples/go.mod
  2. 2
      examples/go.sum
  3. 4
      examples/http/gin/main.go
  4. 0
      examples/http/mux/main.go
  5. 14
      examples/registry/consul/client/main.go
  6. 14
      examples/registry/etcd/client/main.go
  7. 6
      examples/registry/etcd/server/main.go

@ -7,7 +7,7 @@ require (
github.com/gin-gonic/gin v1.6.3 github.com/gin-gonic/gin v1.6.3
github.com/go-kratos/consul v0.0.0-20210311161349-cfb0345e820d github.com/go-kratos/consul v0.0.0-20210311161349-cfb0345e820d
github.com/go-kratos/etcd v0.0.0-20210311152824-df5743ff1a11 github.com/go-kratos/etcd v0.0.0-20210311152824-df5743ff1a11
github.com/go-kratos/kratos/v2 v2.0.0-20210311152607-a4409adf164e github.com/go-kratos/kratos/v2 v2.0.0-20210315090606-74272546caa6
github.com/go-playground/validator/v10 v10.4.1 // indirect github.com/go-playground/validator/v10 v10.4.1 // indirect
github.com/go-redis/redis/extra/redisotel v0.2.0 github.com/go-redis/redis/extra/redisotel v0.2.0
github.com/go-redis/redis/v8 v8.6.0 github.com/go-redis/redis/v8 v8.6.0

@ -124,6 +124,8 @@ github.com/go-kratos/etcd v0.0.0-20210311152824-df5743ff1a11 h1:yN0kNvtSmSmTznbv
github.com/go-kratos/etcd v0.0.0-20210311152824-df5743ff1a11/go.mod h1:+1nilFyiWLlYpAWliKnbFhIax79n4l0mOTJhyNw5EEw= github.com/go-kratos/etcd v0.0.0-20210311152824-df5743ff1a11/go.mod h1:+1nilFyiWLlYpAWliKnbFhIax79n4l0mOTJhyNw5EEw=
github.com/go-kratos/kratos/v2 v2.0.0-20210311152607-a4409adf164e h1:x/1thr6sE8fn09HekGNBdBX6PH9T6iacfJor0sDAZ6g= github.com/go-kratos/kratos/v2 v2.0.0-20210311152607-a4409adf164e h1:x/1thr6sE8fn09HekGNBdBX6PH9T6iacfJor0sDAZ6g=
github.com/go-kratos/kratos/v2 v2.0.0-20210311152607-a4409adf164e/go.mod h1:oLvFyDBJkkWN8TPqb+NmpvRrSy9uM/K+XQubVRc11a8= github.com/go-kratos/kratos/v2 v2.0.0-20210311152607-a4409adf164e/go.mod h1:oLvFyDBJkkWN8TPqb+NmpvRrSy9uM/K+XQubVRc11a8=
github.com/go-kratos/kratos/v2 v2.0.0-20210315090606-74272546caa6 h1:iaZamLO1uUf5NBWXZ1WxP12baWhXNySwW3gUDtCkl+4=
github.com/go-kratos/kratos/v2 v2.0.0-20210315090606-74272546caa6/go.mod h1:oLvFyDBJkkWN8TPqb+NmpvRrSy9uM/K+XQubVRc11a8=
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4= github.com/go-openapi/inflect v0.19.0/go.mod h1:lHpZVlpIQqLyKwJ4N+YSc9hchQy/i12fJykb83CRBH4=

@ -5,7 +5,7 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/go-kratos/kratos/v2" "github.com/go-kratos/kratos/v2"
transhttp "github.com/go-kratos/kratos/v2/transport/http" "github.com/go-kratos/kratos/v2/transport/http"
) )
func main() { func main() {
@ -13,7 +13,7 @@ func main() {
router.GET("/home", func(ctx *gin.Context) { router.GET("/home", func(ctx *gin.Context) {
ctx.String(200, "Hello Gin!") ctx.String(200, "Hello Gin!")
}) })
httpSrv := transhttp.NewServer(transhttp.Address(":8000")) httpSrv := http.NewServer(http.Address(":8000"))
httpSrv.HandlePrefix("/", router) httpSrv.HandlePrefix("/", router)
app := kratos.New( app := kratos.New(

@ -5,8 +5,8 @@ import (
"log" "log"
"github.com/go-kratos/consul/registry" "github.com/go-kratos/consul/registry"
pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" "github.com/go-kratos/kratos/examples/helloworld/helloworld"
transgrpc "github.com/go-kratos/kratos/v2/transport/grpc" "github.com/go-kratos/kratos/v2/transport/grpc"
"github.com/hashicorp/consul/api" "github.com/hashicorp/consul/api"
) )
@ -16,16 +16,16 @@ func main() {
panic(err) panic(err)
} }
r := registry.New(cli) r := registry.New(cli)
conn, err := transgrpc.DialInsecure( conn, err := grpc.DialInsecure(
context.Background(), context.Background(),
transgrpc.WithEndpoint("discovery://d/helloworld"), grpc.WithEndpoint("discovery:///helloworld"),
transgrpc.WithDiscovery(r), grpc.WithDiscovery(r),
) )
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
client := pb.NewGreeterClient(conn) client := helloworld.NewGreeterClient(conn)
reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "kratos"}) reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"})
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

@ -5,8 +5,8 @@ import (
"log" "log"
"github.com/go-kratos/etcd/registry" "github.com/go-kratos/etcd/registry"
pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" "github.com/go-kratos/kratos/examples/helloworld/helloworld"
transgrpc "github.com/go-kratos/kratos/v2/transport/grpc" "github.com/go-kratos/kratos/v2/transport/grpc"
clientv3 "go.etcd.io/etcd/client/v3" clientv3 "go.etcd.io/etcd/client/v3"
) )
@ -18,16 +18,16 @@ func main() {
panic(err) panic(err)
} }
r := registry.New(cli) r := registry.New(cli)
conn, err := transgrpc.DialInsecure( conn, err := grpc.DialInsecure(
context.Background(), context.Background(),
transgrpc.WithEndpoint("discovery://d/helloworld"), grpc.WithEndpoint("discovery:///helloworld"),
transgrpc.WithDiscovery(r), grpc.WithDiscovery(r),
) )
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
client := pb.NewGreeterClient(conn) client := helloworld.NewGreeterClient(conn)
reply, err := client.SayHello(context.Background(), &pb.HelloRequest{Name: "kratos"}) reply, err := client.SayHello(context.Background(), &helloworld.HelloRequest{Name: "kratos"})
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

@ -9,7 +9,7 @@ import (
pb "github.com/go-kratos/kratos/examples/helloworld/helloworld" pb "github.com/go-kratos/kratos/examples/helloworld/helloworld"
"github.com/go-kratos/kratos/v2" "github.com/go-kratos/kratos/v2"
"github.com/go-kratos/kratos/v2/transport/grpc" "github.com/go-kratos/kratos/v2/transport/grpc"
clientv3 "go.etcd.io/etcd/client/v3" etcd "go.etcd.io/etcd/client/v3"
) )
// server is used to implement helloworld.GreeterServer. // server is used to implement helloworld.GreeterServer.
@ -30,11 +30,11 @@ func main() {
s := &server{} s := &server{}
pb.RegisterGreeterServer(grpcSrv, s) pb.RegisterGreeterServer(grpcSrv, s)
cli, err := clientv3.New(clientv3.Config{ cli, err := etcd.New(etcd.Config{
Endpoints: []string{"127.0.0.1:2379"}, Endpoints: []string{"127.0.0.1:2379"},
}) })
if err != nil { if err != nil {
panic(err) log.Fatal(err)
} }
r := registry.New(cli) r := registry.New(cli)
app := kratos.New( app := kratos.New(

Loading…
Cancel
Save