├── go.work ├── v3 ├── registry │ └── etcd │ │ ├── plugins.go │ │ ├── main.go │ │ └── README.md ├── config │ └── etcd │ │ ├── go.mod │ │ ├── README.md │ │ └── main.go ├── helloworld │ ├── proto │ │ ├── helloworld.proto │ │ ├── helloworld.pb.micro.go │ │ └── helloworld.pb.go │ ├── README.md │ ├── client │ │ └── main.go │ └── server │ │ └── main.go ├── README.md ├── event │ ├── proto │ │ ├── statistics.proto │ │ ├── statistics.pb.micro.go │ │ └── statistics.pb.go │ ├── server │ │ ├── handler.go │ │ ├── subscriber.go │ │ └── main.go │ ├── README.md │ └── client │ │ └── main.go ├── web │ ├── README.md │ └── main.go ├── broker │ └── kafka │ │ ├── server │ │ └── main.go │ │ ├── README.md │ │ └── client │ │ └── main.go ├── gateway │ ├── README.md │ └── main.go ├── stream │ ├── README.md │ ├── proto │ │ ├── route_guide.proto │ │ └── route_guide.pb.micro.go │ ├── server │ │ └── main.go │ └── client │ │ └── main.go └── go.mod ├── v4 ├── proto │ ├── message.proto │ ├── helloworld.proto │ ├── message.pb.micro.go │ ├── statistics.proto │ ├── helloworld.pb.micro.go │ ├── statistics.pb.micro.go │ ├── route_guide.proto │ ├── message.pb.go │ ├── helloworld.pb.go │ ├── statistics.pb.go │ └── route_guide.pb.micro.go ├── helloworld │ ├── README.md │ ├── client │ │ └── main.go │ └── server │ │ └── main.go ├── opentelemetry │ ├── README.md │ ├── carrier.go │ └── main.go ├── event │ ├── server │ │ ├── handler.go │ │ ├── subscriber.go │ │ └── main.go │ ├── README.md │ └── client │ │ └── main.go ├── metadata │ ├── client │ │ └── main.go │ └── server │ │ └── main.go ├── gateway │ ├── README.md │ └── main.go ├── README.md ├── hystrix │ └── main.go ├── jaeger │ └── main.go ├── broker │ ├── server │ │ └── main.go │ ├── client │ │ └── main.go │ └── README.md ├── stream │ ├── README.md │ ├── server │ │ ├── main.go │ │ └── data.go │ └── client │ │ └── main.go └── go.mod ├── v1 ├── go.mod ├── main.go ├── README.md └── helloworld │ ├── proto │ └── helloworld.proto │ ├── README.md │ ├── client │ └── main.go │ └── server │ └── main.go ├── v2 ├── helloworld │ ├── proto │ │ └── helloworld.proto │ ├── README.md │ ├── client │ │ └── main.go │ └── server │ │ └── main.go ├── README.md ├── gateway │ ├── README.md │ └── main.go └── go.mod ├── .gitignore ├── README.md └── LICENSE /go.work: -------------------------------------------------------------------------------- 1 | go 1.21.1 2 | 3 | use ( 4 | ./v3 5 | ./v4 6 | ) 7 | -------------------------------------------------------------------------------- /v3/registry/etcd/plugins.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | _ "github.com/asim/go-micro/plugins/registry/etcd/v3" 5 | _ "github.com/asim/go-micro/plugins/server/grpc/v3" 6 | ) 7 | -------------------------------------------------------------------------------- /v4/proto/message.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "../proto"; 4 | 5 | message Message { 6 | string id = 1; 7 | string message = 2; 8 | int64 timestamp = 3; 9 | } 10 | -------------------------------------------------------------------------------- /v1/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/xpunch/go-micro-example/v1 2 | 3 | go 1.13 4 | 5 | require ( 6 | github.com/golang/protobuf v1.5.0 7 | github.com/micro/go-micro v1.18.0 8 | google.golang.org/protobuf v1.27.1 9 | ) 10 | -------------------------------------------------------------------------------- /v1/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "github.com/micro/go-micro" 4 | 5 | func main() { 6 | srv := micro.NewService() 7 | srv.Init() 8 | if err := srv.Run(); err != nil { 9 | log.Fatal(err) 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /v3/config/etcd/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/xpunch/go-micro-example/v3/config/etcd 2 | 3 | go 1.16 4 | 5 | require ( 6 | github.com/asim/go-micro/plugins/config/source/etcd/v3 v3.7.1 // indirect 7 | github.com/asim/go-micro/v3 v3.7.0 8 | ) 9 | -------------------------------------------------------------------------------- /v1/README.md: -------------------------------------------------------------------------------- 1 | # Go-Micro V1 2 | 3 | ## Tools 4 | 5 | ### micro 6 | 7 | ``` 8 | go get github.com/micro/micro@v1.8.0 9 | ``` 10 | 11 | ### protoc-gen-micro 12 | 13 | ``` 14 | go install github.com/micro/protoc-gen-micro@v1.0.0 15 | ``` 16 | -------------------------------------------------------------------------------- /v4/proto/helloworld.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "../proto"; 4 | 5 | service Helloworld { 6 | rpc Call(Request) returns (Response) {} 7 | } 8 | 9 | message Request { string name = 1; } 10 | 11 | message Response { string message = 1; } -------------------------------------------------------------------------------- /v1/helloworld/proto/helloworld.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "../proto"; 4 | 5 | service Helloworld { 6 | rpc Call(Request) returns (Response) {} 7 | } 8 | 9 | message Request { string name = 1; } 10 | 11 | message Response { string message = 1; } -------------------------------------------------------------------------------- /v2/helloworld/proto/helloworld.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "../proto"; 4 | 5 | service Helloworld { 6 | rpc Call(Request) returns (Response) {} 7 | } 8 | 9 | message Request { string name = 1; } 10 | 11 | message Response { string message = 1; } -------------------------------------------------------------------------------- /v3/helloworld/proto/helloworld.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "../proto"; 4 | 5 | service Helloworld { 6 | rpc Call(Request) returns (Response) {} 7 | } 8 | 9 | message Request { string name = 1; } 10 | 11 | message Response { string message = 1; } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, build with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # IDE 15 | .vscode 16 | .idea 17 | 18 | # Protobuf 19 | # *.pb.go 20 | # *.pb.micro.go -------------------------------------------------------------------------------- /v2/README.md: -------------------------------------------------------------------------------- 1 | # Go-Micro V2 2 | 3 | ## Tools 4 | 5 | ### micro 6 | 7 | ``` 8 | go get github.com/micro/micro/v2@v2.9.1 9 | ``` 10 | 11 | ### protoc-gen-micro 12 | ``` 13 | go install github.com/micro/protoc-gen-micro@v2.1.0 14 | ``` 15 | or 16 | ``` 17 | go install github.com/micro/micro/cmd/protoc-gen-micro@v0.0.0-20200728170142-c7f7e4a71077 18 | ``` 19 | -------------------------------------------------------------------------------- /v4/proto/message.pb.micro.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-micro. DO NOT EDIT. 2 | // source: proto/message.proto 3 | 4 | package proto 5 | 6 | import ( 7 | fmt "fmt" 8 | proto "google.golang.org/protobuf/proto" 9 | math "math" 10 | ) 11 | 12 | // Reference imports to suppress errors if they are not otherwise used. 13 | var _ = proto.Marshal 14 | var _ = fmt.Errorf 15 | var _ = math.Inf 16 | -------------------------------------------------------------------------------- /v3/README.md: -------------------------------------------------------------------------------- 1 | # Go-Micro V3 2 | 3 | ## Tools 4 | 5 | ### Protobuf 6 | 7 | ``` 8 | go install github.com/asim/go-micro/cmd/protoc-gen-micro/v3@latest 9 | ``` 10 | 11 | ``` 12 | protoc --go_out=event/proto --micro_out=event/proto event/proto/statistics.proto 13 | protoc --go_out=helloworld/proto --micro_out=helloworld/proto helloworld/proto/helloworld.proto 14 | protoc --go_out=stream/proto --micro_out=stream/proto stream/proto/route_guide.proto 15 | ``` 16 | -------------------------------------------------------------------------------- /v2/helloworld/README.md: -------------------------------------------------------------------------------- 1 | # Hello World 2 | This example demonstrates how to write grpc server and client. 3 | > 1. Generate protobuf files. 4 | > 2. Implement your service, and register with micro service. 5 | 6 | ## Protobuf 7 | ``` 8 | protoc --go_out=proto --micro_out=proto proto/helloworld.proto 9 | ``` 10 | 11 | ## Run Server 12 | ``` 13 | go run server/main.go --server_name helloworld 14 | ``` 15 | 16 | ## Run Client 17 | ``` 18 | go run client/main.go 19 | ``` -------------------------------------------------------------------------------- /v3/helloworld/README.md: -------------------------------------------------------------------------------- 1 | # Hello World 2 | This example demonstrates how to write grpc server and client. 3 | > 1. Generate protobuf files. 4 | > 2. Implement your service, and register with micro service. 5 | 6 | ## Protobuf 7 | ``` 8 | protoc --go_out=proto --micro_out=proto proto/helloworld.proto 9 | ``` 10 | 11 | ## Run Server 12 | ``` 13 | go run server/main.go --server_name helloworld 14 | ``` 15 | 16 | ## Run Client 17 | ``` 18 | go run client/main.go 19 | ``` -------------------------------------------------------------------------------- /v1/helloworld/README.md: -------------------------------------------------------------------------------- 1 | # Hello World 2 | This example demonstrates how to write go micro server and client. 3 | > 1. Generate protobuf files. 4 | > 2. Implement your service, and register with micro service. 5 | 6 | ## Protobuf 7 | ``` 8 | protoc --go_out=proto --micro_out=proto proto/helloworld.proto 9 | ``` 10 | 11 | ## Run Server 12 | ``` 13 | go run server/main.go --server_name helloworld 14 | ``` 15 | 16 | ## Run Client 17 | ``` 18 | go run client/main.go 19 | ``` -------------------------------------------------------------------------------- /v3/config/etcd/README.md: -------------------------------------------------------------------------------- 1 | # ETCD 2 | 3 | ``` 4 | etcdctl put /key {"""k1""":"""v1""""} 5 | ``` 6 | ``` 7 | etcdctl put /key {"""k1""":"""v2""""} 8 | etcdctl put /key {"""k1""":"""v2"""","""k2""":"""v3"""} 9 | ``` 10 | 11 | ``` 12 | go run . 13 | 2021-12-17 11:59:45 file=etcd/main.go:24 level=info {"k1":"v1"} 14 | 2021-12-17 11:59:55 file=etcd/main.go:38 level=info [watcher] {"k1":"v2"} 15 | 2021-12-17 11:59:58 file=etcd/main.go:38 level=info [watcher] {"k1":"v2","k2":"v3"} 16 | ``` -------------------------------------------------------------------------------- /v4/proto/statistics.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "../proto"; 4 | 5 | service StatisticsService { 6 | rpc Statistics(StatisticsRequest) returns (StatisticsReply) {} 7 | } 8 | 9 | message StatisticsRequest { optional string method = 1; } 10 | 11 | message StatisticsReply { int64 access_count = 1; } 12 | 13 | message AccessEvent { 14 | uint32 status = 1; 15 | string method = 2; 16 | string path = 3; 17 | string ip = 4; 18 | int64 latency = 5; 19 | int64 timestamp = 6; 20 | } -------------------------------------------------------------------------------- /v3/event/proto/statistics.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "../proto"; 4 | 5 | service StatisticsService { 6 | rpc Statistics(StatisticsRequest) returns (StatisticsReply) {} 7 | } 8 | 9 | message StatisticsRequest { optional string method = 1; } 10 | 11 | message StatisticsReply { int64 access_count = 1; } 12 | 13 | message AccessEvent { 14 | uint32 status = 1; 15 | string method = 2; 16 | string path = 3; 17 | string ip = 4; 18 | int64 latency = 5; 19 | int64 timestamp = 6; 20 | } -------------------------------------------------------------------------------- /v1/helloworld/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "log" 6 | 7 | "github.com/micro/go-micro" 8 | "github.com/xpunch/go-micro-example/v1/helloworld/proto" 9 | ) 10 | 11 | func main() { 12 | srv := micro.NewService(micro.Name("client")) 13 | srv.Init() 14 | 15 | greeter := proto.NewHelloworldService("helloworld", srv.Client()) 16 | resp, err := greeter.Call(context.TODO(), &proto.Request{Name: "Client"}) 17 | if err != nil { 18 | log.Fatal(err) 19 | } 20 | log.Print(resp) 21 | } 22 | -------------------------------------------------------------------------------- /v4/helloworld/README.md: -------------------------------------------------------------------------------- 1 | # Hello World 2 | This example demonstrates how to write grpc server and client. 3 | > 1. Generate protobuf files. 4 | > 2. Implement your service, and register with micro service. 5 | 6 | ## Protobuf 7 | ``` 8 | protoc --go_out=proto --micro_out=proto proto/helloworld.proto 9 | ``` 10 | 11 | 12 | ## GRPC 13 | ### Run Server 14 | ``` 15 | go run server/main.go --server grpc --server_name helloworld.srv 16 | ``` 17 | 18 | ### Run Client 19 | ``` 20 | go run client/main.go --client grpc 21 | ``` -------------------------------------------------------------------------------- /v4/opentelemetry/README.md: -------------------------------------------------------------------------------- 1 | # Hello World 2 | This example demonstrates how to write grpc server and client. 3 | > 1. Generate protobuf files. 4 | > 2. Implement your service, and register with micro service. 5 | 6 | ## Protobuf 7 | ``` 8 | protoc --go_out=proto --micro_out=proto proto/helloworld.proto 9 | ``` 10 | 11 | 12 | ## GRPC 13 | ### Run Server 14 | ``` 15 | go run server/main.go --server grpc --server_name helloworld.srv 16 | ``` 17 | 18 | ### Run Client 19 | ``` 20 | go run client/main.go --client grpc 21 | ``` -------------------------------------------------------------------------------- /v2/helloworld/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/micro/go-micro/v2" 7 | "github.com/micro/go-micro/v2/logger" 8 | "github.com/xpunch/go-micro-example/v2/helloworld/proto" 9 | ) 10 | 11 | func main() { 12 | srv := micro.NewService(micro.Name("client")) 13 | srv.Init() 14 | 15 | greeter := proto.NewHelloworldService("helloworld", srv.Client()) 16 | resp, err := greeter.Call(context.TODO(), &proto.Request{Name: "Client"}) 17 | if err != nil { 18 | logger.Fatal(err) 19 | } 20 | logger.Info(resp) 21 | } 22 | -------------------------------------------------------------------------------- /v3/web/README.md: -------------------------------------------------------------------------------- 1 | # Web Service 2 | 3 | Use go-micro to handle http request with gin. 4 | 5 | ## Usage 6 | 7 | ``` 8 | 1. create micro service with http server 9 | 2. create gin router 10 | 3. register server handler with router 11 | ``` 12 | 13 | ## Run 14 | 15 | web service 16 | 17 | ``` 18 | go run web/main.go 19 | ``` 20 | 21 | helloworld service 22 | 23 | ``` 24 | go run helloworld/server/main.go 25 | ``` 26 | 27 | ## Testing 28 | 29 | ``` 30 | curl -X POST http://localhost:80/helloworld -d "{"""user""":"""test"""}" 31 | ``` 32 | 33 | ``` 34 | {"message":"Hello test"} 35 | ``` 36 | -------------------------------------------------------------------------------- /v4/event/server/handler.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "sync/atomic" 6 | 7 | pb "github.com/xpunch/go-micro-example/v4/proto" 8 | ) 9 | 10 | type handler struct{} 11 | 12 | func (h *handler) Statistics(ctx context.Context, in *pb.StatisticsRequest, out *pb.StatisticsReply) error { 13 | if in.Method == nil || len(*in.Method) == 0 { 14 | out.AccessCount = atomic.LoadInt64(&AccessCount) 15 | } else { 16 | mu.RLock() 17 | defer mu.RUnlock() 18 | v, ok := AccessMethods[*in.Method] 19 | if ok { 20 | out.AccessCount = v 21 | } 22 | } 23 | return nil 24 | } 25 | -------------------------------------------------------------------------------- /v3/event/server/handler.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "sync/atomic" 6 | 7 | pb "github.com/xpunch/go-micro-example/v3/event/proto" 8 | ) 9 | 10 | type handler struct{} 11 | 12 | func (h *handler) Statistics(ctx context.Context, in *pb.StatisticsRequest, out *pb.StatisticsReply) error { 13 | if in.Method == nil || len(*in.Method) == 0 { 14 | out.AccessCount = atomic.LoadInt64(&AccessCount) 15 | } else { 16 | mu.RLock() 17 | defer mu.RUnlock() 18 | v, ok := AccessMethods[*in.Method] 19 | if ok { 20 | out.AccessCount = v 21 | } 22 | } 23 | return nil 24 | } 25 | -------------------------------------------------------------------------------- /v3/helloworld/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/asim/go-micro/plugins/client/grpc/v3" 7 | "github.com/asim/go-micro/v3" 8 | "github.com/asim/go-micro/v3/logger" 9 | pb "github.com/xpunch/go-micro-example/v3/helloworld/proto" 10 | ) 11 | 12 | func main() { 13 | srv := micro.NewService(micro.Client(grpc.NewClient()), micro.Name("client")) 14 | srv.Init() 15 | 16 | greeter := pb.NewHelloworldService("helloworld", srv.Client()) 17 | resp, err := greeter.Call(context.TODO(), &pb.Request{Name: "Client"}) 18 | if err != nil { 19 | logger.Fatal(err) 20 | } 21 | logger.Info(resp) 22 | } 23 | -------------------------------------------------------------------------------- /v4/helloworld/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | _ "github.com/go-micro/plugins/v4/client/grpc" 7 | _ "github.com/go-micro/plugins/v4/registry/etcd" 8 | pb "github.com/xpunch/go-micro-example/v4/proto" 9 | "go-micro.dev/v4" 10 | "go-micro.dev/v4/logger" 11 | ) 12 | 13 | func main() { 14 | srv := micro.NewService( 15 | micro.Name("helloworld.cli"), 16 | ) 17 | srv.Init() 18 | 19 | greeter := pb.NewHelloworldService("helloworld.srv", srv.Client()) 20 | resp, err := greeter.Call(context.TODO(), &pb.Request{Name: "Client"}) 21 | if err != nil { 22 | logger.Fatal(err) 23 | } 24 | logger.Info(resp) 25 | } 26 | -------------------------------------------------------------------------------- /v1/helloworld/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "log" 6 | 7 | "github.com/micro/go-micro" 8 | "github.com/xpunch/go-micro-example/v1/helloworld/proto" 9 | ) 10 | 11 | type HelloWorld struct{} 12 | 13 | func (h *HelloWorld) Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error { 14 | rsp.Message = "Hello " + req.Name 15 | return nil 16 | } 17 | 18 | func main() { 19 | srv := micro.NewService(micro.Name("helloworld")) 20 | srv.Init() 21 | if err := proto.RegisterHelloworldHandler(srv.Server(), new(HelloWorld)); err != nil { 22 | log.Fatal(err) 23 | } 24 | if err := srv.Run(); err != nil { 25 | log.Fatal(err) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /v4/event/server/subscriber.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "sync/atomic" 6 | 7 | pb "github.com/xpunch/go-micro-example/v4/proto" 8 | "go-micro.dev/v4/logger" 9 | ) 10 | 11 | type subscriber struct{} 12 | 13 | func (s *subscriber) AccessLog(ctx context.Context, l *pb.AccessEvent) error { 14 | defer func() { 15 | if e := recover(); e != nil { 16 | logger.Error("panic: %v", e) 17 | } 18 | }() 19 | logger.Info(l) 20 | atomic.AddInt64(&AccessCount, 1) 21 | mu.Lock() 22 | defer mu.Unlock() 23 | v, ok := AccessMethods[l.Method] 24 | if ok { 25 | AccessMethods[l.Method] = v + 1 26 | } else { 27 | AccessMethods[l.Method] = 1 28 | } 29 | return nil 30 | } 31 | -------------------------------------------------------------------------------- /v3/event/server/subscriber.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "sync/atomic" 6 | 7 | "github.com/asim/go-micro/v3/logger" 8 | pb "github.com/xpunch/go-micro-example/v3/event/proto" 9 | ) 10 | 11 | type subscriber struct{} 12 | 13 | func (s *subscriber) AccessLog(ctx context.Context, l *pb.AccessEvent) error { 14 | defer func() { 15 | if e := recover(); e != nil { 16 | logger.Error("panic: %v", e) 17 | } 18 | }() 19 | logger.Info(l) 20 | atomic.AddInt64(&AccessCount, 1) 21 | mu.Lock() 22 | defer mu.Unlock() 23 | v, ok := AccessMethods[l.Method] 24 | if ok { 25 | AccessMethods[l.Method] = v + 1 26 | } else { 27 | AccessMethods[l.Method] = 1 28 | } 29 | return nil 30 | } 31 | -------------------------------------------------------------------------------- /v3/registry/etcd/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/asim/go-micro/v3" 7 | "github.com/asim/go-micro/v3/logger" 8 | pb "github.com/xpunch/go-micro-example/v3/helloworld/proto" 9 | ) 10 | 11 | type HelloWorld struct{} 12 | 13 | func (h *HelloWorld) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error { 14 | rsp.Message = "Hello " + req.Name 15 | return nil 16 | } 17 | 18 | func main() { 19 | srv := micro.NewService(micro.Name("helloworld")) 20 | srv.Init() 21 | if err := pb.RegisterHelloworldHandler(srv.Server(), new(HelloWorld)); err != nil { 22 | logger.Fatal(err) 23 | } 24 | if err := srv.Run(); err != nil { 25 | logger.Fatal(err) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /v4/metadata/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | _ "github.com/go-micro/plugins/v4/client/grpc" 7 | _ "github.com/go-micro/plugins/v4/registry/etcd" 8 | pb "github.com/xpunch/go-micro-example/v4/proto" 9 | "go-micro.dev/v4" 10 | "go-micro.dev/v4/logger" 11 | "go-micro.dev/v4/metadata" 12 | ) 13 | 14 | func main() { 15 | srv := micro.NewService( 16 | micro.Name("helloworld.cli"), 17 | ) 18 | srv.Init() 19 | 20 | greeter := pb.NewHelloworldService("helloworld.srv", srv.Client()) 21 | ctx := metadata.Set(context.TODO(), "name", "World") 22 | resp, err := greeter.Call(ctx, &pb.Request{}) 23 | if err != nil { 24 | logger.Fatal(err) 25 | } 26 | logger.Info(resp) 27 | } 28 | -------------------------------------------------------------------------------- /v2/helloworld/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/micro/go-micro/v2" 7 | "github.com/micro/go-micro/v2/logger" 8 | "github.com/xpunch/go-micro-example/v2/helloworld/proto" 9 | ) 10 | 11 | type HelloWorld struct{} 12 | 13 | func (h *HelloWorld) Call(ctx context.Context, req *proto.Request, rsp *proto.Response) error { 14 | rsp.Message = "Hello " + req.Name 15 | return nil 16 | } 17 | 18 | func main() { 19 | srv := micro.NewService(micro.Name("helloworld")) 20 | srv.Init() 21 | if err := proto.RegisterHelloworldHandler(srv.Server(), new(HelloWorld)); err != nil { 22 | logger.Fatal(err) 23 | } 24 | if err := srv.Run(); err != nil { 25 | logger.Fatal(err) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /v3/registry/etcd/README.md: -------------------------------------------------------------------------------- 1 | # ETCD 2 | This example demonstrates how to use plugins, and it shows us how to use etcd as registry instead of default mdns. 3 | 4 | ## Run 5 | ``` 6 | go run main.go plugins.go --registry etcd --server grpc --server_name helloworld 7 | ``` 8 | ``` 9 | Registry [etcd] Registering node: helloworld-cfeccaf2-28cc-4d4e-8eea-55c60a9d33ce 10 | ``` 11 | 12 | ## Metadata 13 | ``` 14 | curl http://localhost:8080/helloworld/nodes 15 | ``` 16 | ```json 17 | [{ 18 | "id": "helloworld-7779ad77-8836-46e8-9b4d-e7993e764fd5", 19 | "address": "127.0.0.1:54834", 20 | "metadata": { 21 | "broker": "http", 22 | "protocol": "grpc", 23 | "registry": "etcd", 24 | "server": "grpc", 25 | "transport": "grpc" 26 | } 27 | }] 28 | ``` -------------------------------------------------------------------------------- /v3/broker/kafka/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | _ "github.com/asim/go-micro/plugins/broker/kafka/v3" 7 | "github.com/asim/go-micro/v3" 8 | "github.com/asim/go-micro/v3/logger" 9 | ) 10 | 11 | type Message struct { 12 | ID string `json:"id"` 13 | Timestamp int64 `json:"ts"` 14 | } 15 | 16 | func main() { 17 | srv := micro.NewService( 18 | micro.Name("kafka-server"), 19 | ) 20 | srv.Init() 21 | if err := srv.Server().Subscribe(srv.Server().NewSubscriber("kafka-topic", subscribe)); err != nil { 22 | logger.Fatal(err) 23 | } 24 | if err := srv.Run(); err != nil { 25 | logger.Fatal(err) 26 | } 27 | } 28 | 29 | func subscribe(ctx context.Context, msg *Message) error { 30 | logger.Info(msg) 31 | return nil 32 | } 33 | -------------------------------------------------------------------------------- /v2/gateway/README.md: -------------------------------------------------------------------------------- 1 | # Gateway 2 | This example demonstrates how to implement an gateway forward http request into grpc services. 3 | 4 | # Run 5 | ``` 6 | go run main.go 7 | ``` 8 | 9 | ## Access grpc services through http 10 | ### Endpoint: helloworld 11 | ### Method: Helloworld.Call 12 | ``` 13 | curl -X POST http://localhost:8080/helloworld/Helloworld.Call -H "Content-Type:application/json" -d "{"""name""":"""Joe"""}" 14 | ``` 15 | ``` 16 | {"message":"Hello Joe"} 17 | ``` 18 | 19 | ## View service nodes 20 | ``` 21 | curl http://localhost:8080/helloworld/nodes 22 | ``` 23 | ``` 24 | [{"id":"helloworld-109f6d75-42cc-43ff-96df-f63260cf5372","address":"127.0.0.1:50000","metadata":{"broker":"http","protocol":"grpc","registry":"mdns","server":"grpc","transport":"grpc"}}] 25 | ``` -------------------------------------------------------------------------------- /v3/gateway/README.md: -------------------------------------------------------------------------------- 1 | # Gateway 2 | This example demonstrates how to implement an gateway forward http request into grpc services. 3 | 4 | # Run 5 | ``` 6 | go run main.go 7 | ``` 8 | 9 | ## Access grpc services through http 10 | ### Endpoint: helloworld 11 | ### Method: Helloworld.Call 12 | ``` 13 | curl -X POST http://localhost:8080/helloworld/Helloworld.Call -H "Content-Type:application/json" -d "{"""name""":"""Joe"""}" 14 | ``` 15 | ``` 16 | {"message":"Hello Joe"} 17 | ``` 18 | 19 | ## View service nodes 20 | ``` 21 | curl http://localhost:8080/helloworld/nodes 22 | ``` 23 | ``` 24 | [{"id":"helloworld-109f6d75-42cc-43ff-96df-f63260cf5372","address":"127.0.0.1:50000","metadata":{"broker":"http","protocol":"grpc","registry":"mdns","server":"grpc","transport":"grpc"}}] 25 | ``` -------------------------------------------------------------------------------- /v4/gateway/README.md: -------------------------------------------------------------------------------- 1 | # Gateway 2 | This example demonstrates how to implement an gateway forward http request into grpc services. 3 | 4 | # Run 5 | ``` 6 | go run main.go 7 | ``` 8 | 9 | ## Access grpc services through http 10 | ### Endpoint: helloworld 11 | ### Method: Helloworld.Call 12 | ``` 13 | curl -X POST http://localhost:8080/helloworld/Helloworld.Call -H "Content-Type:application/json" -d "{"""name""":"""Joe"""}" 14 | ``` 15 | ``` 16 | {"message":"Hello Joe"} 17 | ``` 18 | 19 | ## View service nodes 20 | ``` 21 | curl http://localhost:8080/helloworld/nodes 22 | ``` 23 | ``` 24 | [{"id":"helloworld-109f6d75-42cc-43ff-96df-f63260cf5372","address":"127.0.0.1:50000","metadata":{"broker":"http","protocol":"grpc","registry":"mdns","server":"grpc","transport":"grpc"}}] 25 | ``` -------------------------------------------------------------------------------- /v3/helloworld/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/asim/go-micro/plugins/server/grpc/v3" 7 | "github.com/asim/go-micro/v3" 8 | "github.com/asim/go-micro/v3/logger" 9 | pb "github.com/xpunch/go-micro-example/v3/helloworld/proto" 10 | ) 11 | 12 | type HelloWorld struct{} 13 | 14 | func (h *HelloWorld) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error { 15 | rsp.Message = "Hello " + req.Name 16 | return nil 17 | } 18 | 19 | func main() { 20 | srv := micro.NewService(micro.Server(grpc.NewServer()), micro.Name("helloworld")) 21 | srv.Init() 22 | if err := pb.RegisterHelloworldHandler(srv.Server(), new(HelloWorld)); err != nil { 23 | logger.Fatal(err) 24 | } 25 | if err := srv.Run(); err != nil { 26 | logger.Fatal(err) 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /v4/opentelemetry/carrier.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "go-micro.dev/v4/metadata" 5 | "go.opentelemetry.io/otel/propagation" 6 | ) 7 | 8 | type metadataSupplier struct { 9 | metadata *metadata.Metadata 10 | } 11 | 12 | // assert that metadataSupplier implements the TextMapCarrier interface. 13 | var _ propagation.TextMapCarrier = &metadataSupplier{} 14 | 15 | func (s *metadataSupplier) Get(key string) string { 16 | value, ok := s.metadata.Get(key) 17 | if ok { 18 | return value 19 | } 20 | return "" 21 | } 22 | 23 | func (s *metadataSupplier) Set(key string, value string) { 24 | s.metadata.Set(key, value) 25 | } 26 | 27 | func (s *metadataSupplier) Keys() []string { 28 | out := make([]string, 0, len(*s.metadata)) 29 | for key := range *s.metadata { 30 | out = append(out, key) 31 | } 32 | return out 33 | } 34 | -------------------------------------------------------------------------------- /v4/README.md: -------------------------------------------------------------------------------- 1 | # Go-Micro V4 2 | ``` 3 | go get go-micro.dev/v4@latest 4 | ``` 5 | 6 | ### Protobuf 7 | - Download protoc 8 | ``` 9 | https://github.com/protocolbuffers/protobuf/releases 10 | ``` 11 | - Generator 12 | ``` 13 | go install google.golang.org/protobuf/cmd/protoc-gen-go@latest 14 | go install github.com/go-micro/generator/cmd/protoc-gen-micro@latest 15 | ``` 16 | 17 | ### Micro CLI 18 | ``` 19 | go install github.com/asim/go-micro/cmd/micro@latest 20 | ``` 21 | 22 | ### Dashboard 23 | ``` 24 | go install github.com/go-micro/dashboard@latest 25 | ``` 26 | 27 | ### Protobuf 28 | ``` 29 | protoc --go_out=proto --micro_out=proto proto/helloworld.proto 30 | protoc --go_out=proto --micro_out=proto proto/message.proto 31 | protoc --go_out=proto --micro_out=proto proto/route_guide.proto 32 | protoc --go_out=proto --micro_out=proto proto/statistics.proto 33 | ``` -------------------------------------------------------------------------------- /v3/config/etcd/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "os" 5 | "os/signal" 6 | 7 | "github.com/asim/go-micro/plugins/config/source/etcd/v3" 8 | "github.com/asim/go-micro/v3/config" 9 | "github.com/asim/go-micro/v3/logger" 10 | ) 11 | 12 | func main() { 13 | exit := make(chan os.Signal, 1) 14 | signal.Notify(exit, os.Interrupt) 15 | etcdSource := etcd.NewSource( 16 | etcd.WithAddress("127.0.0.1:2379"), 17 | etcd.WithPrefix("/key"), 18 | etcd.StripPrefix(true), 19 | ) 20 | err := config.Load(etcdSource) 21 | if err != nil { 22 | logger.Fatal(err) 23 | } 24 | logger.Info(string(config.Bytes())) 25 | 26 | w, err := etcdSource.Watch() 27 | if err != nil { 28 | logger.Fatal(err) 29 | } 30 | defer w.Stop() 31 | go func() { 32 | for { 33 | cs, err := w.Next() 34 | if err != nil { 35 | logger.Error(err) 36 | break 37 | } 38 | logger.Infof("[watcher] %s", cs.Data) 39 | } 40 | }() 41 | <-exit 42 | } 43 | -------------------------------------------------------------------------------- /v4/metadata/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | _ "github.com/go-micro/plugins/v4/registry/etcd" 7 | _ "github.com/go-micro/plugins/v4/server/grpc" 8 | pb "github.com/xpunch/go-micro-example/v4/proto" 9 | "go-micro.dev/v4" 10 | "go-micro.dev/v4/logger" 11 | "go-micro.dev/v4/metadata" 12 | ) 13 | 14 | type HelloWorld struct{} 15 | 16 | func (h *HelloWorld) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error { 17 | if name, ok := metadata.Get(ctx, "name"); ok { 18 | rsp.Message = "Hello " + name 19 | } else { 20 | rsp.Message = "Hello " + req.Name 21 | } 22 | return nil 23 | } 24 | 25 | func main() { 26 | srv := micro.NewService( 27 | micro.Name("helloworld.srv"), 28 | ) 29 | srv.Init() 30 | if err := pb.RegisterHelloworldHandler(srv.Server(), new(HelloWorld)); err != nil { 31 | logger.Fatal(err) 32 | } 33 | if err := srv.Run(); err != nil { 34 | logger.Fatal(err) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /v3/broker/kafka/README.md: -------------------------------------------------------------------------------- 1 | # Kafka 2 | Use kafka as broker to publish and subscribe event messages. 3 | 4 | ## Plugin 5 | ``` 6 | import _ "github.com/asim/go-micro/plugins/broker/kafka/v3" 7 | ``` 8 | Or my custom plugin: 9 | ``` 10 | import _ "github.com/x-punch/micro-kafka/v3" 11 | ``` 12 | 13 | ## Run 14 | ### Client 15 | ``` 16 | go run kafka/client/main.go --broker kafka --broker_address 127.0.0.1:9092 17 | ``` 18 | ### Server 19 | ``` 20 | go run kafka/server/main.go --broker kafka --broker_address 127.0.0.1:9092 21 | ``` 22 | 23 | ## Testing 24 | ``` 25 | 2021-09-26 17:04:03 file=server/rpc_server.go:840 level=info Broker [kafka] Connected to 127.0.0.1:9092 26 | 2021-09-26 17:04:03 file=server/rpc_server.go:706 level=info Subscribing to topic: kafka-topic 27 | 2021-09-26 17:04:04 file=server/main.go:30 level=info &{f2e1a241-a67d-484d-9026-2bd682736347 1632647044} 28 | 2021-09-26 17:04:05 file=server/main.go:30 level=info &{85684f0d-0e6d-432c-9369-c2a8385d9065 1632647045} 29 | ``` 30 | -------------------------------------------------------------------------------- /v4/event/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sync" 5 | 6 | mgrpc "github.com/go-micro/plugins/v4/server/grpc" 7 | pb "github.com/xpunch/go-micro-example/v4/proto" 8 | "go-micro.dev/v4" 9 | "go-micro.dev/v4/logger" 10 | ) 11 | 12 | var ( 13 | AccessCount int64 14 | AccessMethods map[string]int64 15 | mu sync.RWMutex 16 | ) 17 | 18 | func main() { 19 | srv := micro.NewService( 20 | micro.Server(mgrpc.NewServer()), 21 | micro.Name("statistics"), 22 | micro.Address(":8082"), 23 | ) 24 | srv.Init() 25 | hdl := &handler{} 26 | if err := pb.RegisterStatisticsServiceHandler(srv.Server(), hdl); err != nil { 27 | logger.Fatal(err) 28 | } 29 | sub := &subscriber{} 30 | if err := srv.Server().Subscribe(srv.Server().NewSubscriber("accesslogs", sub.AccessLog)); err != nil { 31 | logger.Fatal(err) 32 | } 33 | if err := srv.Run(); err != nil { 34 | logger.Fatal(err) 35 | } 36 | } 37 | 38 | func init() { 39 | AccessMethods = make(map[string]int64) 40 | } 41 | -------------------------------------------------------------------------------- /v3/event/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "sync" 5 | 6 | mgrpc "github.com/asim/go-micro/plugins/server/grpc/v3" 7 | "github.com/asim/go-micro/v3" 8 | "github.com/asim/go-micro/v3/logger" 9 | pb "github.com/xpunch/go-micro-example/v3/event/proto" 10 | ) 11 | 12 | var ( 13 | AccessCount int64 14 | AccessMethods map[string]int64 15 | mu sync.RWMutex 16 | ) 17 | 18 | func main() { 19 | srv := micro.NewService( 20 | micro.Server(mgrpc.NewServer()), 21 | micro.Name("statistics"), 22 | micro.Address(":8082"), 23 | ) 24 | srv.Init() 25 | hdl := &handler{} 26 | if err := pb.RegisterStatisticsServiceHandler(srv.Server(), hdl); err != nil { 27 | logger.Fatal(err) 28 | } 29 | sub := &subscriber{} 30 | if err := srv.Server().Subscribe(srv.Server().NewSubscriber("accesslogs", sub.AccessLog)); err != nil { 31 | logger.Fatal(err) 32 | } 33 | if err := srv.Run(); err != nil { 34 | logger.Fatal(err) 35 | } 36 | } 37 | 38 | func init() { 39 | AccessMethods = make(map[string]int64) 40 | } 41 | -------------------------------------------------------------------------------- /v3/broker/kafka/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | _ "github.com/asim/go-micro/plugins/broker/kafka/v3" 8 | mgrpc "github.com/asim/go-micro/plugins/client/grpc/v3" 9 | "github.com/asim/go-micro/v3" 10 | "github.com/asim/go-micro/v3/client" 11 | "github.com/asim/go-micro/v3/logger" 12 | "github.com/google/uuid" 13 | ) 14 | 15 | type Message struct { 16 | ID string `json:"id"` 17 | Timestamp int64 `json:"ts"` 18 | } 19 | 20 | func main() { 21 | srv := micro.NewService( 22 | micro.Name("kafka-client"), 23 | micro.Client(mgrpc.NewClient()), 24 | ) 25 | srv.Init() 26 | go func() { 27 | t := time.Tick(time.Second) 28 | for range t { 29 | c := srv.Client() 30 | msg := c.NewMessage("kafka-topic", Message{ID: uuid.NewString(), Timestamp: time.Now().Unix()}, client.WithMessageContentType("application/json")) 31 | if err := c.Publish(context.TODO(), msg); err != nil { 32 | logger.Error(err) 33 | } 34 | } 35 | }() 36 | if err := srv.Run(); err != nil { 37 | logger.Fatal(err) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /v3/event/README.md: -------------------------------------------------------------------------------- 1 | # Event 2 | 3 | This example demonstrates how to handle event between client and server. 4 | 5 | > 1. Client will publish access event when handle http request. 6 | > 2. Server will subscribe access event and update access statistics. 7 | 8 | ## Protobuf 9 | 10 | ``` 11 | protoc --go_out=proto --micro_out=proto proto/statistics.proto 12 | ``` 13 | 14 | ## Run Server 15 | 16 | ``` 17 | go run event/server/main.go event/server/handler.go event/server/subscriber.go 18 | ``` 19 | ### Tips 20 | > Panic recover is required in subscribe method to prevent crash when panic occur in subscribe goroutine. 21 | 22 | ## Run Client 23 | 24 | ``` 25 | go run event/client/main.go 26 | ``` 27 | 28 | ## Testing 29 | ``` 30 | curl -X POST http://localhost:80/helloworld?user=test 31 | {"message":"Hello test"} 32 | ``` 33 | ``` 34 | curl -X GET http://localhost:80/statistics?method=POST 35 | {"access_count":1} 36 | ``` 37 | ``` 38 | curl -X GET http://localhost:80/statistics?method=GET 39 | {"access_count":1} 40 | ``` 41 | ``` 42 | curl -X GET http://localhost:80/statistics 43 | {"access_count":3} 44 | ``` -------------------------------------------------------------------------------- /v4/event/README.md: -------------------------------------------------------------------------------- 1 | # Event 2 | 3 | This example demonstrates how to handle event between client and server. 4 | 5 | > 1. Client will publish access event when handle http request. 6 | > 2. Server will subscribe access event and update access statistics. 7 | 8 | ## Protobuf 9 | 10 | ``` 11 | protoc --go_out=proto --micro_out=proto proto/statistics.proto 12 | ``` 13 | 14 | ## Run Server 15 | 16 | ``` 17 | go run event/server/main.go event/server/handler.go event/server/subscriber.go 18 | ``` 19 | ### Tips 20 | > Panic recover is required in subscribe method to prevent crash when panic occur in subscribe goroutine. 21 | 22 | ## Run Client 23 | 24 | ``` 25 | go run event/client/main.go 26 | ``` 27 | 28 | ## Testing 29 | ``` 30 | curl -X POST http://localhost:80/helloworld?user=test 31 | {"message":"Hello test"} 32 | ``` 33 | ``` 34 | curl -X GET http://localhost:80/statistics?method=POST 35 | {"access_count":1} 36 | ``` 37 | ``` 38 | curl -X GET http://localhost:80/statistics?method=GET 39 | {"access_count":1} 40 | ``` 41 | ``` 42 | curl -X GET http://localhost:80/statistics 43 | {"access_count":3} 44 | ``` -------------------------------------------------------------------------------- /v4/hystrix/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "sync" 6 | 7 | _ "github.com/go-micro/plugins/v4/client/grpc" 8 | _ "github.com/go-micro/plugins/v4/registry/etcd" 9 | mhystrix "github.com/go-micro/plugins/v4/wrapper/breaker/hystrix" 10 | pb "github.com/xpunch/go-micro-example/v4/proto" 11 | "go-micro.dev/v4" 12 | "go-micro.dev/v4/logger" 13 | ) 14 | 15 | func main() { 16 | srv := micro.NewService( 17 | micro.Name("helloworld.cli"), 18 | ) 19 | opts := []micro.Option{} 20 | mhystrix.ConfigureDefault(mhystrix.CommandConfig{MaxConcurrentRequests: 1}) 21 | opts = append(opts, micro.WrapClient(mhystrix.NewClientWrapper(mhystrix.WithFilter(func(c context.Context, e error) bool { 22 | return e == nil || e.Error() == "ignore me" 23 | })))) 24 | srv.Init(opts...) 25 | greeter := pb.NewHelloworldService("helloworld.srv", srv.Client()) 26 | wg := sync.WaitGroup{} 27 | for i := 0; i < 10; i++ { 28 | wg.Add(1) 29 | go func() { 30 | defer wg.Done() 31 | resp, err := greeter.Call(context.TODO(), &pb.Request{Name: "Client"}) 32 | if err != nil { 33 | logger.Error(err) 34 | } else { 35 | logger.Info(resp) 36 | } 37 | }() 38 | } 39 | wg.Wait() 40 | } 41 | -------------------------------------------------------------------------------- /v4/jaeger/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | _ "github.com/go-micro/plugins/v4/client/grpc" 7 | _ "github.com/go-micro/plugins/v4/registry/etcd" 8 | mopentracing "github.com/go-micro/plugins/v4/wrapper/trace/opentracing" 9 | "github.com/opentracing/opentracing-go" 10 | jaegercfg "github.com/uber/jaeger-client-go/config" 11 | pb "github.com/xpunch/go-micro-example/v4/proto" 12 | "go-micro.dev/v4" 13 | "go-micro.dev/v4/logger" 14 | ) 15 | 16 | func main() { 17 | srv := micro.NewService( 18 | micro.Name("helloworld.cli"), 19 | ) 20 | 21 | tracer, closer, err := jaegercfg.Configuration{ServiceName: "helloworld.cli", 22 | Reporter: &jaegercfg.ReporterConfig{LogSpans: true, CollectorEndpoint: "http://127.0.0.1:14268/api/traces"}, 23 | }.NewTracer() 24 | if err != nil { 25 | logger.Fatal(err) 26 | } 27 | defer closer.Close() 28 | opentracing.SetGlobalTracer(tracer) 29 | srv.Init(micro.WrapClient(mopentracing.NewClientWrapper(tracer))) 30 | 31 | greeter := pb.NewHelloworldService("helloworld.srv", srv.Client()) 32 | resp, err := greeter.Call(context.TODO(), &pb.Request{Name: "Client"}) 33 | if err != nil { 34 | logger.Fatal(err) 35 | } 36 | logger.Info(resp) 37 | } 38 | -------------------------------------------------------------------------------- /v4/broker/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | 6 | _ "github.com/go-micro/plugins/v4/broker/kafka" 7 | _ "github.com/go-micro/plugins/v4/broker/mqtt" 8 | _ "github.com/go-micro/plugins/v4/registry/etcd" 9 | pb "github.com/xpunch/go-micro-example/v4/proto" 10 | "go-micro.dev/v4" 11 | "go-micro.dev/v4/logger" 12 | ) 13 | 14 | type Message struct { 15 | ID string `json:"id"` 16 | Message string `json:"message"` 17 | Timestamp int64 `json:"timestamp"` 18 | } 19 | 20 | type subscriber struct{} 21 | 22 | func (s *subscriber) Subscribe(ctx context.Context, msg *pb.Message) error { 23 | logger.Info(msg) 24 | return nil 25 | } 26 | 27 | func subscribe(ctx context.Context, msg *Message) error { 28 | logger.Info(msg) 29 | return nil 30 | } 31 | 32 | func main() { 33 | srv := micro.NewService( 34 | micro.Name("broker-server"), 35 | ) 36 | srv.Init() 37 | if err := micro.RegisterSubscriber("micro.topic.json", srv.Server(), subscribe); err != nil { 38 | logger.Fatal(err) 39 | } 40 | if err := micro.RegisterSubscriber("micro.topic.protobuf", srv.Server(), &subscriber{}); err != nil { 41 | logger.Fatal(err) 42 | } 43 | if err := srv.Run(); err != nil { 44 | logger.Fatal(err) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /v3/stream/README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | This example is translate [go grpc example](https://grpc.io/docs/languages/go/basics/) into go-micro. 4 | You can also find the orignal codes in [github.com/grpc/grpc-go](https://github.com/grpc/grpc-go/tree/master/examples/route_guide). 5 | 6 | # Notes 7 | 8 | - Not support client.SendClose(), details in [issue #2212](https://github.com/asim/go-micro/issues/2212). 9 | 10 | ```go 11 | // used to present stream.CloseAndRecv() in grpc 12 | if err := stream.Send(&pb.Point{Latitude: INT32_MAX, Longitude: INT32_MAX}); err != nil { 13 | logger.Fatal(err) 14 | } 15 | ``` 16 | ``` 17 | if err == io.EOF || proto.Equal(point, invalidPoint) { 18 | break 19 | } 20 | ``` 21 | 22 | - Do not forgot to close grpc stream connection. 23 | 24 | ```go 25 | stream, err := client.RouteChat(ctx) 26 | if err != nil { 27 | logger.Fatal(err) 28 | } 29 | // IMPORTANT: do not forgot to close stream 30 | defer stream.Close() 31 | ``` 32 | 33 | # Run the sample code 34 | 35 | ## Protobuf 36 | 37 | ``` 38 | protoc --go_out=proto --micro_out=proto proto/route_guide.proto 39 | ``` 40 | 41 | ## Server 42 | 43 | ``` 44 | cd stream/server 45 | go run . 46 | ``` 47 | 48 | ## Client 49 | 50 | ``` 51 | cd stream/client 52 | go run main.go 53 | ``` 54 | -------------------------------------------------------------------------------- /v4/stream/README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | 3 | This example is translate [go grpc example](https://grpc.io/docs/languages/go/basics/) into go-micro. 4 | You can also find the orignal codes in [github.com/grpc/grpc-go](https://github.com/grpc/grpc-go/tree/master/examples/route_guide). 5 | 6 | # Notes 7 | 8 | - Not support client.SendClose(), details in [issue #2212](https://github.com/asim/go-micro/issues/2212). 9 | 10 | ```go 11 | // used to present stream.CloseAndRecv() in grpc 12 | if err := stream.Send(&pb.Point{Latitude: INT32_MAX, Longitude: INT32_MAX}); err != nil { 13 | logger.Fatal(err) 14 | } 15 | ``` 16 | ``` 17 | if err == io.EOF || proto.Equal(point, invalidPoint) { 18 | break 19 | } 20 | ``` 21 | 22 | - Do not forgot to close grpc stream connection. 23 | 24 | ```go 25 | stream, err := client.RouteChat(ctx) 26 | if err != nil { 27 | logger.Fatal(err) 28 | } 29 | // IMPORTANT: do not forgot to close stream 30 | defer stream.Close() 31 | ``` 32 | 33 | # Run the sample code 34 | 35 | ## Protobuf 36 | 37 | ``` 38 | protoc --go_out=proto --micro_out=proto proto/route_guide.proto 39 | ``` 40 | 41 | ## Server 42 | 43 | ``` 44 | cd stream/server 45 | go run . 46 | ``` 47 | 48 | ## Client 49 | 50 | ``` 51 | cd stream/client 52 | go run main.go 53 | ``` 54 | -------------------------------------------------------------------------------- /v3/web/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "github.com/asim/go-micro/plugins/client/grpc/v3" 5 | "github.com/asim/go-micro/plugins/server/http/v3" 6 | "github.com/asim/go-micro/v3" 7 | "github.com/asim/go-micro/v3/logger" 8 | "github.com/gin-gonic/gin" 9 | pb "github.com/xpunch/go-micro-example/v3/helloworld/proto" 10 | ) 11 | 12 | func main() { 13 | srv := micro.NewService( 14 | micro.Server(http.NewServer()), 15 | micro.Client(grpc.NewClient()), 16 | micro.Name("web"), 17 | micro.Address(":80"), 18 | ) 19 | srv.Init() 20 | router := gin.New() 21 | router.Use(gin.Recovery()) 22 | router.Use(gin.Logger()) 23 | helloworldService := pb.NewHelloworldService("helloworld", srv.Client()) 24 | router.POST("/helloworld", func(ctx *gin.Context) { 25 | var req struct { 26 | User string `json:"user"` 27 | } 28 | if err := ctx.ShouldBindJSON(&req); err != nil { 29 | ctx.AbortWithStatusJSON(400, err) 30 | return 31 | } 32 | resp, err := helloworldService.Call(ctx, &pb.Request{Name: req.User}) 33 | if err != nil { 34 | ctx.AbortWithStatusJSON(500, err) 35 | return 36 | } 37 | ctx.JSON(200, resp) 38 | }) 39 | if err := micro.RegisterHandler(srv.Server(), router); err != nil { 40 | logger.Fatal(err) 41 | } 42 | if err := srv.Run(); err != nil { 43 | logger.Fatal(err) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /v4/broker/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "sync/atomic" 7 | "time" 8 | 9 | _ "github.com/go-micro/plugins/v4/broker/kafka" 10 | _ "github.com/go-micro/plugins/v4/broker/mqtt" 11 | _ "github.com/go-micro/plugins/v4/registry/etcd" 12 | "github.com/google/uuid" 13 | pb "github.com/xpunch/go-micro-example/v4/proto" 14 | "go-micro.dev/v4" 15 | "go-micro.dev/v4/client" 16 | "go-micro.dev/v4/logger" 17 | ) 18 | 19 | type message struct { 20 | ID string `json:"id"` 21 | Message string `json:"message"` 22 | Timestamp int64 `json:"timestamp"` 23 | } 24 | 25 | func main() { 26 | srv := micro.NewService( 27 | micro.Name("broker-client"), 28 | ) 29 | srv.Init() 30 | var count int32 31 | go func() { 32 | t := time.NewTicker(5 * time.Second) 33 | for range t.C { 34 | m := &message{ 35 | ID: uuid.New().String(), 36 | Message: fmt.Sprintf("No. %d", atomic.AddInt32(&count, 1)), 37 | Timestamp: time.Now().Unix(), 38 | } 39 | err := srv.Client().Publish(context.TODO(), client.NewMessage("micro.topic.json", m, client.WithMessageContentType("application/json"))) 40 | if err != nil { 41 | logger.Error(err) 42 | } 43 | } 44 | }() 45 | go func() { 46 | event := micro.NewEvent("micro.topic.protobuf", srv.Client()) 47 | t := time.NewTicker(5 * time.Second) 48 | for range t.C { 49 | m := &pb.Message{ 50 | Id: uuid.New().String(), 51 | Message: fmt.Sprintf("No. %d", atomic.AddInt32(&count, 1)), 52 | Timestamp: time.Now().Unix(), 53 | } 54 | err := event.Publish(context.TODO(), m) 55 | if err != nil { 56 | logger.Error(err) 57 | } 58 | } 59 | }() 60 | if err := srv.Run(); err != nil { 61 | logger.Fatal(err) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /v2/gateway/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "io" 6 | "strings" 7 | 8 | "github.com/gin-gonic/gin" 9 | "github.com/micro/go-micro/v2" 10 | "github.com/micro/go-micro/v2/client" 11 | "github.com/micro/go-micro/v2/logger" 12 | "github.com/micro/go-micro/v2/registry" 13 | "github.com/micro/go-micro/v2/web" 14 | ) 15 | 16 | func main() { 17 | srv := micro.NewService() 18 | s := web.NewService(web.MicroService(srv), web.Name("gateway"), web.Address(":8080")) 19 | router := gin.New() 20 | router.Use(gin.Recovery()) 21 | router.Use(gin.Logger()) 22 | router.POST("/:service/:endpoint", func(ctx *gin.Context) { 23 | service, endpoint := ctx.Param("service"), ctx.Param("endpoint") 24 | defer ctx.Request.Body.Close() 25 | data, err := io.ReadAll(ctx.Request.Body) 26 | if err != nil { 27 | logger.Error(err) 28 | ctx.AbortWithStatusJSON(500, err.Error()) 29 | return 30 | } 31 | var request json.RawMessage 32 | if len(data) > 0 { 33 | d := json.NewDecoder(strings.NewReader(string(data))) 34 | d.UseNumber() 35 | if err := d.Decode(&request); err != nil { 36 | logger.Error(err) 37 | ctx.AbortWithStatusJSON(500, err.Error()) 38 | return 39 | } 40 | } 41 | c := srv.Client() 42 | var response json.RawMessage 43 | if err := c.Call(ctx, c.NewRequest(service, endpoint, request, client.WithContentType("application/json")), &response); err != nil { 44 | logger.Error(err) 45 | ctx.AbortWithStatusJSON(500, err.Error()) 46 | return 47 | } 48 | ctx.JSON(200, response) 49 | }) 50 | router.GET("/:service/nodes", func(ctx *gin.Context) { 51 | services, err := srv.Options().Registry.GetService(ctx.Param("service")) 52 | if err != nil { 53 | logger.Error(err) 54 | ctx.AbortWithStatusJSON(500, err.Error()) 55 | return 56 | } 57 | if len(services) == 0 { 58 | ctx.AbortWithStatusJSON(400, "service not found") 59 | return 60 | } 61 | nodes := make([]*registry.Node, 0) 62 | for _, s := range services { 63 | nodes = append(nodes, s.Nodes...) 64 | } 65 | ctx.JSON(200, nodes) 66 | }) 67 | s.Init(web.Handler(router)) 68 | if err := s.Run(); err != nil { 69 | logger.Fatal(err) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /v4/event/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "time" 5 | 6 | "github.com/gin-gonic/gin" 7 | mgrpc "github.com/go-micro/plugins/v4/client/grpc" 8 | mhttp "github.com/go-micro/plugins/v4/server/http" 9 | pb "github.com/xpunch/go-micro-example/v4/proto" 10 | pbh "github.com/xpunch/go-micro-example/v4/proto" 11 | "go-micro.dev/v4" 12 | "go-micro.dev/v4/logger" 13 | ) 14 | 15 | func main() { 16 | srv := micro.NewService( 17 | micro.Server(mhttp.NewServer()), 18 | micro.Client(mgrpc.NewClient()), 19 | micro.Name("web"), 20 | micro.Address(":80"), 21 | ) 22 | srv.Init() 23 | accessEvent := micro.NewEvent("accesslogs", srv.Client()) 24 | router := gin.New() 25 | router.Use(gin.Recovery(), gin.Logger(), AccessLogMiddleware(accessEvent)) 26 | helloworldService := pbh.NewHelloworldService("helloworld", srv.Client()) 27 | statisticsService := pb.NewStatisticsService("statistics", srv.Client()) 28 | router.POST("/helloworld", func(ctx *gin.Context) { 29 | resp, err := helloworldService.Call(ctx, &pbh.Request{Name: ctx.Query("user")}) 30 | if err != nil { 31 | ctx.AbortWithStatusJSON(500, err) 32 | return 33 | } 34 | ctx.JSON(200, resp) 35 | }) 36 | router.GET("/statistics", func(ctx *gin.Context) { 37 | method := ctx.Query("method") 38 | resp, err := statisticsService.Statistics(ctx, &pb.StatisticsRequest{Method: &method}) 39 | if err != nil { 40 | ctx.AbortWithStatusJSON(500, err) 41 | return 42 | } 43 | ctx.JSON(200, resp) 44 | }) 45 | if err := micro.RegisterHandler(srv.Server(), router); err != nil { 46 | logger.Fatal(err) 47 | } 48 | if err := srv.Run(); err != nil { 49 | logger.Error(err) 50 | } 51 | } 52 | 53 | func AccessLogMiddleware(event micro.Event) gin.HandlerFunc { 54 | return func(ctx *gin.Context) { 55 | start := time.Now() 56 | path := ctx.Request.URL.EscapedPath() 57 | ctx.Next() 58 | method := ctx.Request.Method 59 | latency := time.Since(start) 60 | err := event.Publish(ctx, &pb.AccessEvent{ 61 | Status: uint32(ctx.Writer.Status()), 62 | Method: method, 63 | Path: path, 64 | Ip: ctx.ClientIP(), 65 | Latency: int64(latency), 66 | Timestamp: start.Unix(), 67 | }) 68 | if err != nil { 69 | logger.Warn(err) 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /v3/event/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "time" 5 | 6 | mgrpc "github.com/asim/go-micro/plugins/client/grpc/v3" 7 | mhttp "github.com/asim/go-micro/plugins/server/http/v3" 8 | "github.com/asim/go-micro/v3" 9 | "github.com/asim/go-micro/v3/logger" 10 | "github.com/gin-gonic/gin" 11 | pb "github.com/xpunch/go-micro-example/v3/event/proto" 12 | pbh "github.com/xpunch/go-micro-example/v3/helloworld/proto" 13 | ) 14 | 15 | func main() { 16 | srv := micro.NewService( 17 | micro.Server(mhttp.NewServer()), 18 | micro.Client(mgrpc.NewClient()), 19 | micro.Name("web"), 20 | micro.Address(":80"), 21 | ) 22 | srv.Init() 23 | accessEvent := micro.NewEvent("accesslogs", srv.Client()) 24 | router := gin.New() 25 | router.Use(gin.Recovery(), gin.Logger(), AccessLogMiddleware(accessEvent)) 26 | helloworldService := pbh.NewHelloworldService("helloworld", srv.Client()) 27 | statisticsService := pb.NewStatisticsService("statistics", srv.Client()) 28 | router.POST("/helloworld", func(ctx *gin.Context) { 29 | resp, err := helloworldService.Call(ctx, &pbh.Request{Name: ctx.Query("user")}) 30 | if err != nil { 31 | ctx.AbortWithStatusJSON(500, err) 32 | return 33 | } 34 | ctx.JSON(200, resp) 35 | }) 36 | router.GET("/statistics", func(ctx *gin.Context) { 37 | method := ctx.Query("method") 38 | resp, err := statisticsService.Statistics(ctx, &pb.StatisticsRequest{Method: &method}) 39 | if err != nil { 40 | ctx.AbortWithStatusJSON(500, err) 41 | return 42 | } 43 | ctx.JSON(200, resp) 44 | }) 45 | if err := micro.RegisterHandler(srv.Server(), router); err != nil { 46 | logger.Fatal(err) 47 | } 48 | if err := srv.Run(); err != nil { 49 | logger.Error(err) 50 | } 51 | } 52 | 53 | func AccessLogMiddleware(event micro.Event) gin.HandlerFunc { 54 | return func(ctx *gin.Context) { 55 | start := time.Now() 56 | path := ctx.Request.URL.EscapedPath() 57 | ctx.Next() 58 | method := ctx.Request.Method 59 | latency := time.Since(start) 60 | err := event.Publish(ctx, &pb.AccessEvent{ 61 | Status: uint32(ctx.Writer.Status()), 62 | Method: method, 63 | Path: path, 64 | Ip: ctx.ClientIP(), 65 | Latency: int64(latency), 66 | Timestamp: start.Unix(), 67 | }) 68 | if err != nil { 69 | logger.Warn(err) 70 | } 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /v4/proto/helloworld.pb.micro.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-micro. DO NOT EDIT. 2 | // source: proto/helloworld.proto 3 | 4 | package proto 5 | 6 | import ( 7 | fmt "fmt" 8 | proto "google.golang.org/protobuf/proto" 9 | math "math" 10 | ) 11 | 12 | import ( 13 | context "context" 14 | api "go-micro.dev/v4/api" 15 | client "go-micro.dev/v4/client" 16 | server "go-micro.dev/v4/server" 17 | ) 18 | 19 | // Reference imports to suppress errors if they are not otherwise used. 20 | var _ = proto.Marshal 21 | var _ = fmt.Errorf 22 | var _ = math.Inf 23 | 24 | // Reference imports to suppress errors if they are not otherwise used. 25 | var _ api.Endpoint 26 | var _ context.Context 27 | var _ client.Option 28 | var _ server.Option 29 | 30 | // Api Endpoints for Helloworld service 31 | 32 | func NewHelloworldEndpoints() []*api.Endpoint { 33 | return []*api.Endpoint{} 34 | } 35 | 36 | // Client API for Helloworld service 37 | 38 | type HelloworldService interface { 39 | Call(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) 40 | } 41 | 42 | type helloworldService struct { 43 | c client.Client 44 | name string 45 | } 46 | 47 | func NewHelloworldService(name string, c client.Client) HelloworldService { 48 | return &helloworldService{ 49 | c: c, 50 | name: name, 51 | } 52 | } 53 | 54 | func (c *helloworldService) Call(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) { 55 | req := c.c.NewRequest(c.name, "Helloworld.Call", in) 56 | out := new(Response) 57 | err := c.c.Call(ctx, req, out, opts...) 58 | if err != nil { 59 | return nil, err 60 | } 61 | return out, nil 62 | } 63 | 64 | // Server API for Helloworld service 65 | 66 | type HelloworldHandler interface { 67 | Call(context.Context, *Request, *Response) error 68 | } 69 | 70 | func RegisterHelloworldHandler(s server.Server, hdlr HelloworldHandler, opts ...server.HandlerOption) error { 71 | type helloworld interface { 72 | Call(ctx context.Context, in *Request, out *Response) error 73 | } 74 | type Helloworld struct { 75 | helloworld 76 | } 77 | h := &helloworldHandler{hdlr} 78 | return s.Handle(s.NewHandler(&Helloworld{h}, opts...)) 79 | } 80 | 81 | type helloworldHandler struct { 82 | HelloworldHandler 83 | } 84 | 85 | func (h *helloworldHandler) Call(ctx context.Context, in *Request, out *Response) error { 86 | return h.HelloworldHandler.Call(ctx, in, out) 87 | } 88 | -------------------------------------------------------------------------------- /v4/gateway/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "io" 6 | "strings" 7 | 8 | "github.com/gin-gonic/gin" 9 | "github.com/go-micro/plugins/v4/client/grpc" 10 | _ "github.com/go-micro/plugins/v4/client/grpc" 11 | _ "github.com/go-micro/plugins/v4/registry/etcd" 12 | "github.com/go-micro/plugins/v4/server/http" 13 | "go-micro.dev/v4" 14 | "go-micro.dev/v4/client" 15 | "go-micro.dev/v4/logger" 16 | "go-micro.dev/v4/registry" 17 | ) 18 | 19 | func main() { 20 | srv := micro.NewService( 21 | micro.Server(http.NewServer()), 22 | micro.Client(grpc.NewClient()), 23 | micro.Name("gateway"), 24 | micro.Address(":8080"), 25 | ) 26 | srv.Init() 27 | router := gin.New() 28 | router.Use(gin.Recovery()) 29 | router.Use(gin.Logger()) 30 | router.POST("/:service/:endpoint", func(ctx *gin.Context) { 31 | service, endpoint := ctx.Param("service"), ctx.Param("endpoint") 32 | defer ctx.Request.Body.Close() 33 | data, err := io.ReadAll(ctx.Request.Body) 34 | if err != nil { 35 | logger.Error(err) 36 | ctx.AbortWithStatusJSON(500, err.Error()) 37 | return 38 | } 39 | var request json.RawMessage 40 | if len(data) > 0 { 41 | d := json.NewDecoder(strings.NewReader(string(data))) 42 | d.UseNumber() 43 | if err := d.Decode(&request); err != nil { 44 | logger.Error(err) 45 | ctx.AbortWithStatusJSON(500, err.Error()) 46 | return 47 | } 48 | } 49 | c := srv.Client() 50 | var response json.RawMessage 51 | if err := c.Call(ctx, c.NewRequest(service, endpoint, request, client.WithContentType("application/json")), &response); err != nil { 52 | logger.Error(err) 53 | ctx.AbortWithStatusJSON(500, err.Error()) 54 | return 55 | } 56 | ctx.JSON(200, response) 57 | }) 58 | router.GET("/:service/nodes", func(ctx *gin.Context) { 59 | services, err := srv.Options().Registry.GetService(ctx.Param("service")) 60 | if err != nil { 61 | logger.Error(err) 62 | ctx.AbortWithStatusJSON(500, err.Error()) 63 | return 64 | } 65 | if len(services) == 0 { 66 | ctx.AbortWithStatusJSON(400, "service not found") 67 | return 68 | } 69 | nodes := make([]*registry.Node, 0) 70 | for _, s := range services { 71 | nodes = append(nodes, s.Nodes...) 72 | } 73 | ctx.JSON(200, nodes) 74 | }) 75 | if err := micro.RegisterHandler(srv.Server(), router); err != nil { 76 | logger.Fatal(err) 77 | } 78 | if err := srv.Run(); err != nil { 79 | logger.Fatal(err) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /v4/broker/README.md: -------------------------------------------------------------------------------- 1 | # Broker 2 | 3 | ## Protobuf 4 | 5 | ``` 6 | protoc --go_out=proto proto/message.proto 7 | ``` 8 | 9 | ## MQTT 10 | 11 | ``` 12 | cd client 13 | go run . --broker mqtt --broker_address 127.0.0.1:1883 14 | ``` 15 | 16 | ``` 17 | cd server 18 | go run . --broker mqtt --broker_address 127.0.0.1:1883 19 | ``` 20 | 21 | ``` 22 | 2021-11-18 13:29:06 file=v4@v4.4.0/service.go:206 level=info Starting [service] mqtt-server 23 | 2021-11-18 13:29:06 file=server/rpc_server.go:820 level=info Transport [http] Listening on [::]:64282 24 | 2021-11-18 13:29:06 file=server/rpc_server.go:840 level=info Broker [mqtt] Connected to tcp://127.0.0.1:1883 25 | 2021-11-18 13:29:06 file=server/rpc_server.go:654 level=info Registry [mdns] Registering node: mqtt-server-286497dc-f8d4-4f0b-afc6-e3181b053fc5 26 | 2021-11-18 13:29:06 file=server/rpc_server.go:706 level=info Subscribing to topic: micro.topic.json 27 | 2021-11-18 13:29:06 file=server/rpc_server.go:706 level=info Subscribing to topic: micro.topic.protobuf 28 | 2021-11-18 13:29:23 file=server/main.go:26 level=info &{92314b4f-d3dd-483c-a793-d711db01a791 No. 1 1637213363} 29 | 2021-11-18 13:29:23 file=server/main.go:21 level=info id:"cae41692-79d8-4a54-b049-6d51a50ba12e" message:"No. 1" timestamp:1637213363 30 | ``` 31 | 32 | ## Kafka 33 | 34 | ``` 35 | cd client 36 | go run . --broker kafka --broker_address 127.0.0.1:9092 37 | ``` 38 | 39 | ``` 40 | cd server 41 | go run . --broker kafka --broker_address 127.0.0.1:9092 42 | ``` 43 | 44 | ``` 45 | 2021-11-26 16:52:30 file=v4@v4.4.0/service.go:206 level=info Starting [service] broker-server 46 | 2021-11-26 16:52:30 file=server/rpc_server.go:820 level=info Transport [http] Listening on [::]:62905 47 | 2021-11-26 16:52:30 file=server/rpc_server.go:840 level=info Broker [kafka] Connected to 127.0.0.1:9092 48 | 2021-11-26 16:52:30 file=server/rpc_server.go:654 level=info Registry [etcd] Registering node: broker-server-aaac2a42-9d77-4db1-84ef-646876e02f32 49 | 2021-11-26 16:52:30 file=server/rpc_server.go:706 level=info Subscribing to topic: micro.topic.json 50 | 2021-11-26 16:52:30 file=server/rpc_server.go:706 level=info Subscribing to topic: micro.topic.protobuf 51 | 2021-11-26 16:52:42 file=server/main.go:23 level=info id:"91e1d77e-d6fe-4138-9dae-52da4565f1bb" message:"No. 1" timestamp:1637916762 52 | 2021-11-26 16:52:42 file=server/main.go:23 level=info id:"9379968d-54a7-44cf-83c0-c295aa275bd4" message:"No. 2" timestamp:1637916762 53 | ``` 54 | -------------------------------------------------------------------------------- /v3/gateway/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "io" 6 | "strings" 7 | 8 | "github.com/asim/go-micro/plugins/client/grpc/v3" 9 | _ "github.com/asim/go-micro/plugins/registry/etcd/v3" 10 | "github.com/asim/go-micro/plugins/server/http/v3" 11 | "github.com/asim/go-micro/v3" 12 | "github.com/asim/go-micro/v3/client" 13 | "github.com/asim/go-micro/v3/logger" 14 | "github.com/asim/go-micro/v3/registry" 15 | "github.com/gin-gonic/gin" 16 | ) 17 | 18 | func main() { 19 | srv := micro.NewService( 20 | micro.Server(http.NewServer()), 21 | micro.Client(grpc.NewClient()), 22 | micro.Name("gateway"), 23 | micro.Address(":8080"), 24 | ) 25 | srv.Init() 26 | router := gin.New() 27 | router.Use(gin.Recovery()) 28 | router.Use(gin.Logger()) 29 | router.POST("/:service/:endpoint", func(ctx *gin.Context) { 30 | service, endpoint := ctx.Param("service"), ctx.Param("endpoint") 31 | defer ctx.Request.Body.Close() 32 | data, err := io.ReadAll(ctx.Request.Body) 33 | if err != nil { 34 | logger.Error(err) 35 | ctx.AbortWithStatusJSON(500, err.Error()) 36 | return 37 | } 38 | var request json.RawMessage 39 | if len(data) > 0 { 40 | d := json.NewDecoder(strings.NewReader(string(data))) 41 | d.UseNumber() 42 | if err := d.Decode(&request); err != nil { 43 | logger.Error(err) 44 | ctx.AbortWithStatusJSON(500, err.Error()) 45 | return 46 | } 47 | } 48 | c := srv.Client() 49 | var response json.RawMessage 50 | if err := c.Call(ctx, c.NewRequest(service, endpoint, request, client.WithContentType("application/json")), &response); err != nil { 51 | logger.Error(err) 52 | ctx.AbortWithStatusJSON(500, err.Error()) 53 | return 54 | } 55 | ctx.JSON(200, response) 56 | }) 57 | router.GET("/:service/nodes", func(ctx *gin.Context) { 58 | services, err := srv.Options().Registry.GetService(ctx.Param("service")) 59 | if err != nil { 60 | logger.Error(err) 61 | ctx.AbortWithStatusJSON(500, err.Error()) 62 | return 63 | } 64 | if len(services) == 0 { 65 | ctx.AbortWithStatusJSON(400, "service not found") 66 | return 67 | } 68 | nodes := make([]*registry.Node, 0) 69 | for _, s := range services { 70 | nodes = append(nodes, s.Nodes...) 71 | } 72 | ctx.JSON(200, nodes) 73 | }) 74 | if err := micro.RegisterHandler(srv.Server(), router); err != nil { 75 | logger.Fatal(err) 76 | } 77 | if err := srv.Run(); err != nil { 78 | logger.Fatal(err) 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /v3/helloworld/proto/helloworld.pb.micro.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-micro. DO NOT EDIT. 2 | // source: helloworld/proto/helloworld.proto 3 | 4 | package proto 5 | 6 | import ( 7 | fmt "fmt" 8 | proto "google.golang.org/protobuf/proto" 9 | math "math" 10 | ) 11 | 12 | import ( 13 | context "context" 14 | api "github.com/asim/go-micro/v3/api" 15 | client "github.com/asim/go-micro/v3/client" 16 | server "github.com/asim/go-micro/v3/server" 17 | ) 18 | 19 | // Reference imports to suppress errors if they are not otherwise used. 20 | var _ = proto.Marshal 21 | var _ = fmt.Errorf 22 | var _ = math.Inf 23 | 24 | // Reference imports to suppress errors if they are not otherwise used. 25 | var _ api.Endpoint 26 | var _ context.Context 27 | var _ client.Option 28 | var _ server.Option 29 | 30 | // Api Endpoints for Helloworld service 31 | 32 | func NewHelloworldEndpoints() []*api.Endpoint { 33 | return []*api.Endpoint{} 34 | } 35 | 36 | // Client API for Helloworld service 37 | 38 | type HelloworldService interface { 39 | Call(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) 40 | } 41 | 42 | type helloworldService struct { 43 | c client.Client 44 | name string 45 | } 46 | 47 | func NewHelloworldService(name string, c client.Client) HelloworldService { 48 | return &helloworldService{ 49 | c: c, 50 | name: name, 51 | } 52 | } 53 | 54 | func (c *helloworldService) Call(ctx context.Context, in *Request, opts ...client.CallOption) (*Response, error) { 55 | req := c.c.NewRequest(c.name, "Helloworld.Call", in) 56 | out := new(Response) 57 | err := c.c.Call(ctx, req, out, opts...) 58 | if err != nil { 59 | return nil, err 60 | } 61 | return out, nil 62 | } 63 | 64 | // Server API for Helloworld service 65 | 66 | type HelloworldHandler interface { 67 | Call(context.Context, *Request, *Response) error 68 | } 69 | 70 | func RegisterHelloworldHandler(s server.Server, hdlr HelloworldHandler, opts ...server.HandlerOption) error { 71 | type helloworld interface { 72 | Call(ctx context.Context, in *Request, out *Response) error 73 | } 74 | type Helloworld struct { 75 | helloworld 76 | } 77 | h := &helloworldHandler{hdlr} 78 | return s.Handle(s.NewHandler(&Helloworld{h}, opts...)) 79 | } 80 | 81 | type helloworldHandler struct { 82 | HelloworldHandler 83 | } 84 | 85 | func (h *helloworldHandler) Call(ctx context.Context, in *Request, out *Response) error { 86 | return h.HelloworldHandler.Call(ctx, in, out) 87 | } 88 | -------------------------------------------------------------------------------- /v4/proto/statistics.pb.micro.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-micro. DO NOT EDIT. 2 | // source: proto/statistics.proto 3 | 4 | package proto 5 | 6 | import ( 7 | fmt "fmt" 8 | proto "google.golang.org/protobuf/proto" 9 | math "math" 10 | ) 11 | 12 | import ( 13 | context "context" 14 | api "go-micro.dev/v4/api" 15 | client "go-micro.dev/v4/client" 16 | server "go-micro.dev/v4/server" 17 | ) 18 | 19 | // Reference imports to suppress errors if they are not otherwise used. 20 | var _ = proto.Marshal 21 | var _ = fmt.Errorf 22 | var _ = math.Inf 23 | 24 | // Reference imports to suppress errors if they are not otherwise used. 25 | var _ api.Endpoint 26 | var _ context.Context 27 | var _ client.Option 28 | var _ server.Option 29 | 30 | // Api Endpoints for StatisticsService service 31 | 32 | func NewStatisticsServiceEndpoints() []*api.Endpoint { 33 | return []*api.Endpoint{} 34 | } 35 | 36 | // Client API for StatisticsService service 37 | 38 | type StatisticsService interface { 39 | Statistics(ctx context.Context, in *StatisticsRequest, opts ...client.CallOption) (*StatisticsReply, error) 40 | } 41 | 42 | type statisticsService struct { 43 | c client.Client 44 | name string 45 | } 46 | 47 | func NewStatisticsService(name string, c client.Client) StatisticsService { 48 | return &statisticsService{ 49 | c: c, 50 | name: name, 51 | } 52 | } 53 | 54 | func (c *statisticsService) Statistics(ctx context.Context, in *StatisticsRequest, opts ...client.CallOption) (*StatisticsReply, error) { 55 | req := c.c.NewRequest(c.name, "StatisticsService.Statistics", in) 56 | out := new(StatisticsReply) 57 | err := c.c.Call(ctx, req, out, opts...) 58 | if err != nil { 59 | return nil, err 60 | } 61 | return out, nil 62 | } 63 | 64 | // Server API for StatisticsService service 65 | 66 | type StatisticsServiceHandler interface { 67 | Statistics(context.Context, *StatisticsRequest, *StatisticsReply) error 68 | } 69 | 70 | func RegisterStatisticsServiceHandler(s server.Server, hdlr StatisticsServiceHandler, opts ...server.HandlerOption) error { 71 | type statisticsService interface { 72 | Statistics(ctx context.Context, in *StatisticsRequest, out *StatisticsReply) error 73 | } 74 | type StatisticsService struct { 75 | statisticsService 76 | } 77 | h := &statisticsServiceHandler{hdlr} 78 | return s.Handle(s.NewHandler(&StatisticsService{h}, opts...)) 79 | } 80 | 81 | type statisticsServiceHandler struct { 82 | StatisticsServiceHandler 83 | } 84 | 85 | func (h *statisticsServiceHandler) Statistics(ctx context.Context, in *StatisticsRequest, out *StatisticsReply) error { 86 | return h.StatisticsServiceHandler.Statistics(ctx, in, out) 87 | } 88 | -------------------------------------------------------------------------------- /v3/event/proto/statistics.pb.micro.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-micro. DO NOT EDIT. 2 | // source: event/proto/statistics.proto 3 | 4 | package proto 5 | 6 | import ( 7 | fmt "fmt" 8 | proto "google.golang.org/protobuf/proto" 9 | math "math" 10 | ) 11 | 12 | import ( 13 | context "context" 14 | api "github.com/asim/go-micro/v3/api" 15 | client "github.com/asim/go-micro/v3/client" 16 | server "github.com/asim/go-micro/v3/server" 17 | ) 18 | 19 | // Reference imports to suppress errors if they are not otherwise used. 20 | var _ = proto.Marshal 21 | var _ = fmt.Errorf 22 | var _ = math.Inf 23 | 24 | // Reference imports to suppress errors if they are not otherwise used. 25 | var _ api.Endpoint 26 | var _ context.Context 27 | var _ client.Option 28 | var _ server.Option 29 | 30 | // Api Endpoints for StatisticsService service 31 | 32 | func NewStatisticsServiceEndpoints() []*api.Endpoint { 33 | return []*api.Endpoint{} 34 | } 35 | 36 | // Client API for StatisticsService service 37 | 38 | type StatisticsService interface { 39 | Statistics(ctx context.Context, in *StatisticsRequest, opts ...client.CallOption) (*StatisticsReply, error) 40 | } 41 | 42 | type statisticsService struct { 43 | c client.Client 44 | name string 45 | } 46 | 47 | func NewStatisticsService(name string, c client.Client) StatisticsService { 48 | return &statisticsService{ 49 | c: c, 50 | name: name, 51 | } 52 | } 53 | 54 | func (c *statisticsService) Statistics(ctx context.Context, in *StatisticsRequest, opts ...client.CallOption) (*StatisticsReply, error) { 55 | req := c.c.NewRequest(c.name, "StatisticsService.Statistics", in) 56 | out := new(StatisticsReply) 57 | err := c.c.Call(ctx, req, out, opts...) 58 | if err != nil { 59 | return nil, err 60 | } 61 | return out, nil 62 | } 63 | 64 | // Server API for StatisticsService service 65 | 66 | type StatisticsServiceHandler interface { 67 | Statistics(context.Context, *StatisticsRequest, *StatisticsReply) error 68 | } 69 | 70 | func RegisterStatisticsServiceHandler(s server.Server, hdlr StatisticsServiceHandler, opts ...server.HandlerOption) error { 71 | type statisticsService interface { 72 | Statistics(ctx context.Context, in *StatisticsRequest, out *StatisticsReply) error 73 | } 74 | type StatisticsService struct { 75 | statisticsService 76 | } 77 | h := &statisticsServiceHandler{hdlr} 78 | return s.Handle(s.NewHandler(&StatisticsService{h}, opts...)) 79 | } 80 | 81 | type statisticsServiceHandler struct { 82 | StatisticsServiceHandler 83 | } 84 | 85 | func (h *statisticsServiceHandler) Statistics(ctx context.Context, in *StatisticsRequest, out *StatisticsReply) error { 86 | return h.StatisticsServiceHandler.Statistics(ctx, in, out) 87 | } 88 | -------------------------------------------------------------------------------- /v4/helloworld/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "time" 6 | 7 | _ "github.com/go-micro/plugins/v4/client/grpc" 8 | _ "github.com/go-micro/plugins/v4/registry/etcd" 9 | "github.com/go-micro/plugins/v4/wrapper/trace/opentelemetry" 10 | pb "github.com/xpunch/go-micro-example/v4/proto" 11 | "go-micro.dev/v4" 12 | "go-micro.dev/v4/logger" 13 | "go.opentelemetry.io/otel" 14 | "go.opentelemetry.io/otel/exporters/jaeger" 15 | "go.opentelemetry.io/otel/propagation" 16 | "go.opentelemetry.io/otel/sdk/resource" 17 | tracesdk "go.opentelemetry.io/otel/sdk/trace" 18 | semconv "go.opentelemetry.io/otel/semconv/v1.4.0" 19 | ) 20 | 21 | type HelloWorld struct{} 22 | 23 | func (h *HelloWorld) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error { 24 | rsp.Message = "Hello " + req.Name 25 | // return errors.New("fake error") 26 | return nil 27 | } 28 | 29 | func main() { 30 | name := "helloworld.srv" 31 | srv := micro.NewService() 32 | tp, err := newTracerProvider(name, srv.Server().Options().Id, "http://jaeger-collector:14268/api/traces") 33 | if err != nil { 34 | logger.Fatal(err) 35 | } 36 | otel.SetTracerProvider(tp) 37 | otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) 38 | opts := []micro.Option{ 39 | micro.Name(name), 40 | } 41 | defer func() { 42 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) 43 | defer cancel() 44 | if err := tp.Shutdown(ctx); err != nil { 45 | logger.Fatal(err) 46 | } 47 | }() 48 | opts = append(opts, micro.WrapHandler(opentelemetry.NewHandlerWrapper())) 49 | srv.Init(opts...) 50 | if err := pb.RegisterHelloworldHandler(srv.Server(), new(HelloWorld)); err != nil { 51 | logger.Fatal(err) 52 | } 53 | if err := srv.Run(); err != nil { 54 | logger.Fatal(err) 55 | } 56 | } 57 | 58 | // newTracerProvider returns an OpenTelemetry TracerProvider configured to use 59 | // the Jaeger exporter that will send spans to the provided url. The returned 60 | // TracerProvider will also use a Resource configured with all the information 61 | // about the application. 62 | func newTracerProvider(serviceName, serviceID, url string) (*tracesdk.TracerProvider, error) { 63 | // Create the Jaeger exporter 64 | exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url))) 65 | if err != nil { 66 | return nil, err 67 | } 68 | tp := tracesdk.NewTracerProvider( 69 | tracesdk.WithBatcher(exp), 70 | tracesdk.WithResource(resource.NewWithAttributes( 71 | semconv.SchemaURL, 72 | semconv.ServiceNameKey.String(serviceName), 73 | semconv.ServiceVersionKey.String("latest"), 74 | semconv.ServiceInstanceIDKey.String(serviceID), 75 | )), 76 | ) 77 | return tp, nil 78 | } 79 | -------------------------------------------------------------------------------- /v4/proto/route_guide.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "../proto"; 4 | 5 | package proto; 6 | 7 | // Interface exported by the server. 8 | service RouteGuide { 9 | // A simple RPC. 10 | // 11 | // Obtains the feature at a given position. 12 | // 13 | // A feature with an empty name is returned if there's no feature at the given 14 | // position. 15 | rpc GetFeature(Point) returns (Feature) {} 16 | 17 | // A server-to-client streaming RPC. 18 | // 19 | // Obtains the Features available within the given Rectangle. Results are 20 | // streamed rather than returned at once (e.g. in a response message with a 21 | // repeated field), as the rectangle may cover a large area and contain a 22 | // huge number of features. 23 | rpc ListFeatures(Rectangle) returns (stream Feature) {} 24 | 25 | // A client-to-server streaming RPC. 26 | // 27 | // Accepts a stream of Points on a route being traversed, returning a 28 | // RouteSummary when traversal is completed. 29 | rpc RecordRoute(stream Point) returns (RouteSummary) {} 30 | 31 | // A Bidirectional streaming RPC. 32 | // 33 | // Accepts a stream of RouteNotes sent while a route is being traversed, 34 | // while receiving other RouteNotes (e.g. from other users). 35 | rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} 36 | } 37 | 38 | // Points are represented as latitude-longitude pairs in the E7 representation 39 | // (degrees multiplied by 10**7 and rounded to the nearest integer). 40 | // Latitudes should be in the range +/- 90 degrees and longitude should be in 41 | // the range +/- 180 degrees (inclusive). 42 | message Point { 43 | int32 latitude = 1; 44 | int32 longitude = 2; 45 | } 46 | 47 | // A latitude-longitude rectangle, represented as two diagonally opposite 48 | // points "lo" and "hi". 49 | message Rectangle { 50 | // One corner of the rectangle. 51 | Point lo = 1; 52 | 53 | // The other corner of the rectangle. 54 | Point hi = 2; 55 | } 56 | 57 | // A feature names something at a given point. 58 | // 59 | // If a feature could not be named, the name is empty. 60 | message Feature { 61 | // The name of the feature. 62 | string name = 1; 63 | 64 | // The point where the feature is detected. 65 | Point location = 2; 66 | } 67 | 68 | // A RouteNote is a message sent while at a given point. 69 | message RouteNote { 70 | // The location from which the message is sent. 71 | Point location = 1; 72 | 73 | // The message to be sent. 74 | string message = 2; 75 | } 76 | 77 | // A RouteSummary is received in response to a RecordRoute rpc. 78 | // 79 | // It contains the number of individual points received, the number of 80 | // detected features, and the total distance covered as the cumulative sum of 81 | // the distance between each point. 82 | message RouteSummary { 83 | // The number of points received. 84 | int32 point_count = 1; 85 | 86 | // The number of known features passed while traversing the route. 87 | int32 feature_count = 2; 88 | 89 | // The distance covered in metres. 90 | int32 distance = 3; 91 | 92 | // The duration of the traversal in seconds. 93 | int32 elapsed_time = 4; 94 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Go Micro Example [![View](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fxpunch%2Fgo-micro-example&count_bg=%2379C83D&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com) 2 | 3 | This project demonostrates how to use go-micro to run your application. 4 | 5 | ## [Go Micro V1](https://github.com/xpunch/go-micro-example/tree/main/v1) 6 | 7 | - [Preparation](https://github.com/xpunch/go-micro-example/tree/main/v1/README.md) 8 | - [1.Hello World](https://github.com/xpunch/go-micro-example/tree/main/v1/helloworld) 9 | 10 | ## [Go Micro V2](https://github.com/xpunch/go-micro-example/tree/main/v2) 11 | 12 | - [Preparation](https://github.com/xpunch/go-micro-example/tree/main/v2/README.md) 13 | - [1.Hello World](https://github.com/xpunch/go-micro-example/tree/main/v2/helloworld) 14 | - [2.API Gateway](https://github.com/xpunch/go-micro-example/tree/main/v2/gateway) 15 | 16 | ## [Go Micro V3](https://github.com/xpunch/go-micro-example/tree/main/v3) 17 | 18 | All examples are based on go-micro v3. 19 | 20 | - [Preparation](https://github.com/xpunch/go-micro-example/tree/main/v3/README.md) 21 | - [1.Hello World](https://github.com/xpunch/go-micro-example/tree/main/v3/helloworld) 22 | - [2.API Gateway](https://github.com/xpunch/go-micro-example/tree/main/v3/gateway) 23 | - [3.ETCD(Registry)](https://github.com/xpunch/go-micro-example/tree/main/v3/registry/etcd) 24 | - [4.Web](https://github.com/xpunch/go-micro-example/tree/main/v3/web) 25 | - [5.Event](https://github.com/xpunch/go-micro-example/tree/main/v3/event) 26 | - [6.Stream](https://github.com/xpunch/go-micro-example/tree/main/v3/stream) 27 | - [7.Kafka(Broker)](https://github.com/xpunch/go-micro-example/tree/main/v3/broker/kafka) 28 | - [8.ETCD(Config)](https://github.com/xpunch/go-micro-example/tree/main/v3/config/etcd) 29 | 30 | ## [Go Micro V4](https://github.com/xpunch/go-micro-example/tree/main/v4) 31 | 32 | All examples are based on go-micro.dev/v4. 33 | 34 | - [Preparation](https://github.com/xpunch/go-micro-example/tree/main/v4/README.md) 35 | - [1.Hello World](https://github.com/xpunch/go-micro-example/tree/main/v4/helloworld) 36 | - [2.Stream(Support CloseSend)](https://github.com/xpunch/go-micro-example/tree/main/v4/stream) 37 | - [3.Broker](https://github.com/xpunch/go-micro-example/tree/main/v4/mqtt) 38 | - [4.Metadata](https://github.com/xpunch/go-micro-example/tree/main/v4/metadata) 39 | - [5.Gateway](https://github.com/xpunch/go-micro-example/tree/main/v4/gateway) 40 | - [6.Event](https://github.com/xpunch/go-micro-example/tree/main/v4/event) 41 | - [7.Hystrix](https://github.com/xpunch/go-micro-example/tree/main/v4/hystrix) 42 | - [8.Tracing(jaeger)](https://github.com/xpunch/go-micro-example/tree/main/v4/jaeger) 43 | 44 | ## [Go Micro Dashboard](https://github.com/xpunch/go-micro-dashboard) 45 | 46 | ``` 47 | go install github.com/xpunch/go-micro-dashboard@latest 48 | ``` 49 | 50 | ### Protobuf(https://github.com/protocolbuffers/protobuf/releases) 51 | 52 | ``` 53 | go install github.com/golang/protobuf/protoc-gen-go@latest 54 | ``` 55 | 56 | ### Community 57 | 58 | ``` 59 | QQ Group: 953973712 60 | ``` 61 | -------------------------------------------------------------------------------- /v3/stream/proto/route_guide.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "../proto"; 4 | 5 | package proto; 6 | 7 | // Interface exported by the server. 8 | service RouteGuide { 9 | // A simple RPC. 10 | // 11 | // Obtains the feature at a given position. 12 | // 13 | // A feature with an empty name is returned if there's no feature at the given 14 | // position. 15 | rpc GetFeature(Point) returns (Feature) {} 16 | 17 | // A server-to-client streaming RPC. 18 | // 19 | // Obtains the Features available within the given Rectangle. Results are 20 | // streamed rather than returned at once (e.g. in a response message with a 21 | // repeated field), as the rectangle may cover a large area and contain a 22 | // huge number of features. 23 | rpc ListFeatures(Rectangle) returns (stream Feature) {} 24 | 25 | // A client-to-server streaming RPC. 26 | // 27 | // Accepts a stream of Points on a route being traversed, returning a 28 | // RouteSummary when traversal is completed. 29 | rpc RecordRoute(stream Point) returns (RouteSummary) {} 30 | 31 | // A Bidirectional streaming RPC. 32 | // 33 | // Accepts a stream of RouteNotes sent while a route is being traversed, 34 | // while receiving other RouteNotes (e.g. from other users). 35 | rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} 36 | } 37 | 38 | // Points are represented as latitude-longitude pairs in the E7 representation 39 | // (degrees multiplied by 10**7 and rounded to the nearest integer). 40 | // Latitudes should be in the range +/- 90 degrees and longitude should be in 41 | // the range +/- 180 degrees (inclusive). 42 | message Point { 43 | int32 latitude = 1; 44 | int32 longitude = 2; 45 | } 46 | 47 | // A latitude-longitude rectangle, represented as two diagonally opposite 48 | // points "lo" and "hi". 49 | message Rectangle { 50 | // One corner of the rectangle. 51 | Point lo = 1; 52 | 53 | // The other corner of the rectangle. 54 | Point hi = 2; 55 | } 56 | 57 | // A feature names something at a given point. 58 | // 59 | // If a feature could not be named, the name is empty. 60 | message Feature { 61 | // The name of the feature. 62 | string name = 1; 63 | 64 | // The point where the feature is detected. 65 | Point location = 2; 66 | } 67 | 68 | // A RouteNote is a message sent while at a given point. 69 | message RouteNote { 70 | // The location from which the message is sent. 71 | Point location = 1; 72 | 73 | // The message to be sent. 74 | string message = 2; 75 | } 76 | 77 | // A RouteSummary is received in response to a RecordRoute rpc. 78 | // 79 | // It contains the number of individual points received, the number of 80 | // detected features, and the total distance covered as the cumulative sum of 81 | // the distance between each point. 82 | message RouteSummary { 83 | // The number of points received. 84 | int32 point_count = 1; 85 | 86 | // The number of known features passed while traversing the route. 87 | int32 feature_count = 2; 88 | 89 | // The distance covered in metres. 90 | int32 distance = 3; 91 | 92 | // The duration of the traversal in seconds. 93 | int32 elapsed_time = 4; 94 | } -------------------------------------------------------------------------------- /v4/stream/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "io" 6 | "sync" 7 | "time" 8 | 9 | "github.com/go-micro/plugins/v4/server/grpc" 10 | pb "github.com/xpunch/go-micro-example/v4/proto" 11 | "go-micro.dev/v4" 12 | "go-micro.dev/v4/logger" 13 | "google.golang.org/protobuf/proto" 14 | ) 15 | 16 | type server struct { 17 | mu sync.Mutex 18 | routeNotes map[string][]*pb.RouteNote 19 | } 20 | 21 | func main() { 22 | srv := micro.NewService( 23 | micro.Server(grpc.NewServer()), 24 | micro.Name("stream-server-v4"), 25 | ) 26 | srv.Init() 27 | pb.RegisterRouteGuideHandler(srv.Server(), &server{routeNotes: make(map[string][]*pb.RouteNote)}) 28 | if err := srv.Run(); err != nil { 29 | logger.Fatal(err) 30 | } 31 | } 32 | 33 | func (s *server) GetFeature(ctx context.Context, in *pb.Point, out *pb.Feature) error { 34 | for _, f := range features { 35 | if proto.Equal(f.Location, in) { 36 | out.Location = f.Location 37 | out.Name = f.Name 38 | return nil 39 | } 40 | } 41 | out.Location = in 42 | return nil 43 | } 44 | 45 | func (s *server) ListFeatures(ctx context.Context, in *pb.Rectangle, stream pb.RouteGuide_ListFeaturesStream) error { 46 | for _, feature := range features { 47 | if inRange(feature.Location, in) { 48 | if err := stream.Send(feature); err != nil { 49 | return err 50 | } 51 | } 52 | } 53 | return nil 54 | } 55 | 56 | func (s *server) RecordRoute(ctx context.Context, stream pb.RouteGuide_RecordRouteStream) error { 57 | var pointCount, featureCount, distance int32 58 | var lastPoint *pb.Point 59 | startTime := time.Now() 60 | for { 61 | point, err := stream.Recv() 62 | if err == io.EOF { 63 | break 64 | } 65 | if err != nil { 66 | return err 67 | } 68 | pointCount++ 69 | for _, feature := range features { 70 | if proto.Equal(feature.Location, point) { 71 | featureCount++ 72 | } 73 | } 74 | if lastPoint != nil { 75 | distance += calcDistance(lastPoint, point) 76 | } 77 | lastPoint = point 78 | } 79 | return stream.SendMsg(&pb.RouteSummary{ 80 | PointCount: pointCount, 81 | FeatureCount: featureCount, 82 | Distance: distance, 83 | ElapsedTime: int32(time.Since(startTime).Seconds()), 84 | }) 85 | } 86 | 87 | func (s *server) RouteChat(ctx context.Context, stream pb.RouteGuide_RouteChatStream) error { 88 | for { 89 | in, err := stream.Recv() 90 | if err == io.EOF { 91 | break 92 | } 93 | if err != nil { 94 | return err 95 | } 96 | key := serialize(in.Location) 97 | 98 | s.mu.Lock() 99 | s.routeNotes[key] = append(s.routeNotes[key], in) 100 | // Note: this copy prevents blocking other clients while serving this one. 101 | // We don't need to do a deep copy, because elements in the slice are 102 | // insert-only and never modified. 103 | rn := make([]*pb.RouteNote, len(s.routeNotes[key])) 104 | copy(rn, s.routeNotes[key]) 105 | s.mu.Unlock() 106 | 107 | for _, note := range rn { 108 | if err := stream.Send(note); err != nil { 109 | return err 110 | } 111 | } 112 | } 113 | return nil 114 | } 115 | -------------------------------------------------------------------------------- /v4/opentelemetry/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | "net/http" 7 | "time" 8 | 9 | _ "github.com/go-micro/plugins/v4/registry/etcd" 10 | _ "github.com/go-micro/plugins/v4/server/grpc" 11 | "github.com/go-micro/plugins/v4/wrapper/trace/opentelemetry" 12 | "go-micro.dev/v4" 13 | "go-micro.dev/v4/logger" 14 | "go-micro.dev/v4/metadata" 15 | "go.opentelemetry.io/otel" 16 | "go.opentelemetry.io/otel/exporters/jaeger" 17 | "go.opentelemetry.io/otel/propagation" 18 | "go.opentelemetry.io/otel/sdk/resource" 19 | tracesdk "go.opentelemetry.io/otel/sdk/trace" 20 | semconv "go.opentelemetry.io/otel/semconv/v1.10.0" 21 | 22 | pb "github.com/xpunch/go-micro-example/v4/proto" 23 | ) 24 | 25 | const ( 26 | id = 1 27 | name = "opentelemetry.srv" 28 | version = "latest" 29 | ) 30 | 31 | func main() { 32 | srv := micro.NewService( 33 | micro.Name(name), 34 | ) 35 | tp, err := tracerProvider("http://47.103.38.143:14268/api/traces") 36 | // tp, err := tracerProvider("http://jaeger-collector.default.svc.cluster.local:14268/api/traces") 37 | if err != nil { 38 | logger.Fatal(err) 39 | } 40 | otel.SetTracerProvider(tp) 41 | otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) 42 | srv.Init(micro.WrapClient(opentelemetry.NewClientWrapper())) 43 | // Cleanly shutdown and flush telemetry when the application exits. 44 | defer func(ctx context.Context) { 45 | // Do not make the application hang when it is shutdown. 46 | ctx, cancel := context.WithTimeout(ctx, time.Second*5) 47 | defer cancel() 48 | if err := tp.Shutdown(ctx); err != nil { 49 | logger.Fatal(err) 50 | } 51 | }(context.TODO()) 52 | 53 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 54 | ctx := otel.GetTextMapPropagator().Extract(r.Context(), propagation.HeaderCarrier(r.Header)) 55 | tctx, span := tp.Tracer("/").Start(ctx, "request") 56 | defer span.End() 57 | fmt.Fprintln(w, "hello world") 58 | 59 | md := make(metadata.Metadata, 10) 60 | otel.GetTextMapPropagator().Inject(tctx, &metadataSupplier{metadata: &md}) 61 | fmt.Println(md) 62 | ctx = metadata.NewContext(tctx, md) 63 | greeter := pb.NewHelloworldService("helloworld.srv", srv.Client()) 64 | resp, err := greeter.Call(ctx, &pb.Request{Name: "Client"}) 65 | if err != nil { 66 | logger.Error(err) 67 | } 68 | logger.Info(resp) 69 | }) 70 | http.ListenAndServe("127.0.0.1:8080", nil) 71 | } 72 | 73 | // tracerProvider returns an OpenTelemetry TracerProvider configured to use 74 | // the Jaeger exporter that will send spans to the provided url. The returned 75 | // TracerProvider will also use a Resource configured with all the information 76 | // about the application. 77 | func tracerProvider(url string) (*tracesdk.TracerProvider, error) { 78 | // Create the Jaeger exporter 79 | exp, err := jaeger.New(jaeger.WithCollectorEndpoint(jaeger.WithEndpoint(url))) 80 | if err != nil { 81 | return nil, err 82 | } 83 | tp := tracesdk.NewTracerProvider( 84 | // Always be sure to batch in production. 85 | tracesdk.WithBatcher(exp), 86 | // Record information about this application in a Resource. 87 | tracesdk.WithResource(resource.NewWithAttributes( 88 | semconv.SchemaURL, 89 | semconv.ServiceNameKey.String(name), 90 | semconv.ServiceVersionKey.String(version), 91 | )), 92 | ) 93 | return tp, nil 94 | } 95 | -------------------------------------------------------------------------------- /v3/stream/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "io" 6 | "sync" 7 | "time" 8 | 9 | "github.com/asim/go-micro/plugins/server/grpc/v3" 10 | "github.com/asim/go-micro/v3" 11 | "github.com/asim/go-micro/v3/logger" 12 | pb "github.com/xpunch/go-micro-example/v3/stream/proto" 13 | "google.golang.org/protobuf/proto" 14 | ) 15 | 16 | // INT32_MAX used to present invalid point 17 | const INT32_MAX = int32(^uint32(0) >> 1) 18 | 19 | var invalidPoint = &pb.Point{Latitude: INT32_MAX, Longitude: INT32_MAX} 20 | 21 | type server struct { 22 | mu sync.Mutex 23 | routeNotes map[string][]*pb.RouteNote 24 | } 25 | 26 | func main() { 27 | srv := micro.NewService( 28 | micro.Server(grpc.NewServer()), 29 | micro.Name("stream-server"), 30 | ) 31 | srv.Init() 32 | pb.RegisterRouteGuideHandler(srv.Server(), &server{routeNotes: make(map[string][]*pb.RouteNote)}) 33 | if err := srv.Run(); err != nil { 34 | logger.Fatal(err) 35 | } 36 | } 37 | 38 | func (s *server) GetFeature(ctx context.Context, in *pb.Point, out *pb.Feature) error { 39 | for _, f := range features { 40 | if proto.Equal(f.Location, in) { 41 | out.Location = f.Location 42 | out.Name = f.Name 43 | return nil 44 | } 45 | } 46 | out.Location = in 47 | return nil 48 | } 49 | 50 | func (s *server) ListFeatures(ctx context.Context, in *pb.Rectangle, stream pb.RouteGuide_ListFeaturesStream) error { 51 | for _, feature := range features { 52 | if inRange(feature.Location, in) { 53 | if err := stream.Send(feature); err != nil { 54 | return err 55 | } 56 | } 57 | } 58 | return nil 59 | } 60 | 61 | func (s *server) RecordRoute(ctx context.Context, stream pb.RouteGuide_RecordRouteStream) error { 62 | var pointCount, featureCount, distance int32 63 | var lastPoint *pb.Point 64 | startTime := time.Now() 65 | for { 66 | point, err := stream.Recv() 67 | // TODO: support client.SendClose() 68 | // https://github.com/asim/go-micro/issues/2212 69 | if err == io.EOF || proto.Equal(point, invalidPoint) { 70 | break 71 | } 72 | if err != nil { 73 | return err 74 | } 75 | pointCount++ 76 | for _, feature := range features { 77 | if proto.Equal(feature.Location, point) { 78 | featureCount++ 79 | } 80 | } 81 | if lastPoint != nil { 82 | distance += calcDistance(lastPoint, point) 83 | } 84 | lastPoint = point 85 | } 86 | return stream.SendMsg(&pb.RouteSummary{ 87 | PointCount: pointCount, 88 | FeatureCount: featureCount, 89 | Distance: distance, 90 | ElapsedTime: int32(time.Since(startTime).Seconds()), 91 | }) 92 | } 93 | 94 | func (s *server) RouteChat(ctx context.Context, stream pb.RouteGuide_RouteChatStream) error { 95 | for { 96 | in, err := stream.Recv() 97 | // TODO: should support client.SendClose() 98 | // https://github.com/asim/go-micro/issues/2212 99 | if err == io.EOF || in == nil || in.Location == nil { 100 | break 101 | } 102 | if err != nil { 103 | return err 104 | } 105 | key := serialize(in.Location) 106 | 107 | s.mu.Lock() 108 | s.routeNotes[key] = append(s.routeNotes[key], in) 109 | // Note: this copy prevents blocking other clients while serving this one. 110 | // We don't need to do a deep copy, because elements in the slice are 111 | // insert-only and never modified. 112 | rn := make([]*pb.RouteNote, len(s.routeNotes[key])) 113 | copy(rn, s.routeNotes[key]) 114 | s.mu.Unlock() 115 | 116 | for _, note := range rn { 117 | if err := stream.Send(note); err != nil { 118 | return err 119 | } 120 | } 121 | } 122 | return nil 123 | } 124 | -------------------------------------------------------------------------------- /v2/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/xpunch/go-micro-example/v2 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.7.4 7 | github.com/golang/protobuf v1.4.0 8 | github.com/micro/go-micro/v2 v2.9.1 9 | google.golang.org/protobuf v1.22.0 10 | ) 11 | 12 | require ( 13 | github.com/BurntSushi/toml v0.3.1 // indirect 14 | github.com/bitly/go-simplejson v0.5.0 // indirect 15 | github.com/coreos/etcd v3.3.18+incompatible // indirect 16 | github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f // indirect 17 | github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect 18 | github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect 19 | github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect 20 | github.com/emirpasic/gods v1.12.0 // indirect 21 | github.com/fsnotify/fsnotify v1.4.7 // indirect 22 | github.com/ghodss/yaml v1.0.0 // indirect 23 | github.com/gin-contrib/sse v0.1.0 // indirect 24 | github.com/go-git/gcfg v1.5.0 // indirect 25 | github.com/go-git/go-billy/v5 v5.0.0 // indirect 26 | github.com/go-git/go-git/v5 v5.1.0 // indirect 27 | github.com/go-playground/locales v0.13.0 // indirect 28 | github.com/go-playground/universal-translator v0.17.0 // indirect 29 | github.com/go-playground/validator/v10 v10.4.1 // indirect 30 | github.com/gogo/protobuf v1.2.1 // indirect 31 | github.com/google/uuid v1.1.1 // indirect 32 | github.com/hashicorp/hcl v1.0.0 // indirect 33 | github.com/hpcloud/tail v1.0.0 // indirect 34 | github.com/imdario/mergo v0.3.9 // indirect 35 | github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect 36 | github.com/json-iterator/go v1.1.9 // indirect 37 | github.com/kevinburke/ssh_config v0.0.0-20190725054713-01f96b0aa0cd // indirect 38 | github.com/leodido/go-urn v1.2.0 // indirect 39 | github.com/mattn/go-isatty v0.0.12 // indirect 40 | github.com/micro/cli/v2 v2.1.2 // indirect 41 | github.com/miekg/dns v1.1.27 // indirect 42 | github.com/mitchellh/go-homedir v1.1.0 // indirect 43 | github.com/mitchellh/hashstructure v1.0.0 // indirect 44 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 45 | github.com/modern-go/reflect2 v1.0.1 // indirect 46 | github.com/nats-io/jwt v0.3.2 // indirect 47 | github.com/nats-io/nats.go v1.9.2 // indirect 48 | github.com/nats-io/nkeys v0.1.4 // indirect 49 | github.com/nats-io/nuid v1.0.1 // indirect 50 | github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect 51 | github.com/patrickmn/go-cache v2.1.0+incompatible // indirect 52 | github.com/pkg/errors v0.9.1 // indirect 53 | github.com/russross/blackfriday/v2 v2.0.1 // indirect 54 | github.com/sergi/go-diff v1.1.0 // indirect 55 | github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect 56 | github.com/ugorji/go/codec v1.1.7 // indirect 57 | github.com/xanzy/ssh-agent v0.2.1 // indirect 58 | go.uber.org/atomic v1.5.0 // indirect 59 | go.uber.org/multierr v1.3.0 // indirect 60 | go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee // indirect 61 | go.uber.org/zap v1.13.0 // indirect 62 | golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect 63 | golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f // indirect 64 | golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2 // indirect 65 | golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect 66 | golang.org/x/text v0.3.2 // indirect 67 | golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 // indirect 68 | google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1 // indirect 69 | google.golang.org/grpc v1.26.0 // indirect 70 | gopkg.in/fsnotify.v1 v1.4.7 // indirect 71 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect 72 | gopkg.in/warnings.v0 v0.1.2 // indirect 73 | gopkg.in/yaml.v2 v2.2.8 // indirect 74 | honnef.co/go/tools v0.0.1-2019.2.3 // indirect 75 | ) 76 | -------------------------------------------------------------------------------- /v3/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/xpunch/go-micro-example/v3 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/asim/go-micro/plugins/broker/kafka/v3 v3.7.0 7 | github.com/asim/go-micro/plugins/client/grpc/v3 v3.7.0 8 | github.com/asim/go-micro/plugins/registry/etcd/v3 v3.7.0 9 | github.com/asim/go-micro/plugins/server/grpc/v3 v3.7.0 10 | github.com/asim/go-micro/plugins/server/http/v3 v3.7.0 11 | github.com/asim/go-micro/v3 v3.7.1 12 | github.com/gin-gonic/gin v1.9.1 13 | github.com/google/uuid v1.3.0 14 | google.golang.org/protobuf v1.30.0 15 | ) 16 | 17 | require ( 18 | github.com/Microsoft/go-winio v0.6.0 // indirect 19 | github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect 20 | github.com/Shopify/sarama v1.30.1 // indirect 21 | github.com/acomagu/bufpipe v1.0.3 // indirect 22 | github.com/bitly/go-simplejson v0.5.0 // indirect 23 | github.com/bytedance/sonic v1.9.1 // indirect 24 | github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect 25 | github.com/coreos/go-semver v0.3.0 // indirect 26 | github.com/coreos/go-systemd/v22 v22.3.2 // indirect 27 | github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect 28 | github.com/davecgh/go-spew v1.1.1 // indirect 29 | github.com/eapache/go-resiliency v1.2.0 // indirect 30 | github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect 31 | github.com/eapache/queue v1.1.0 // indirect 32 | github.com/emirpasic/gods v1.12.0 // indirect 33 | github.com/fsnotify/fsnotify v1.6.0 // indirect 34 | github.com/gabriel-vasile/mimetype v1.4.2 // indirect 35 | github.com/gin-contrib/sse v0.1.0 // indirect 36 | github.com/go-git/gcfg v1.5.0 // indirect 37 | github.com/go-git/go-billy/v5 v5.3.1 // indirect 38 | github.com/go-git/go-git/v5 v5.4.2 // indirect 39 | github.com/go-playground/locales v0.14.1 // indirect 40 | github.com/go-playground/universal-translator v0.18.1 // indirect 41 | github.com/go-playground/validator/v10 v10.14.0 // indirect 42 | github.com/goccy/go-json v0.10.2 // indirect 43 | github.com/gogo/protobuf v1.3.2 // indirect 44 | github.com/golang/protobuf v1.5.2 // indirect 45 | github.com/golang/snappy v0.0.4 // indirect 46 | github.com/hashicorp/go-uuid v1.0.2 // indirect 47 | github.com/imdario/mergo v0.3.12 // indirect 48 | github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect 49 | github.com/jcmturner/aescts/v2 v2.0.0 // indirect 50 | github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect 51 | github.com/jcmturner/gofork v1.0.0 // indirect 52 | github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect 53 | github.com/jcmturner/rpc/v2 v2.0.3 // indirect 54 | github.com/json-iterator/go v1.1.12 // indirect 55 | github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect 56 | github.com/klauspost/compress v1.15.9 // indirect 57 | github.com/klauspost/cpuid/v2 v2.2.4 // indirect 58 | github.com/kr/pretty v0.3.0 // indirect 59 | github.com/leodido/go-urn v1.2.4 // indirect 60 | github.com/mattn/go-isatty v0.0.19 // indirect 61 | github.com/miekg/dns v1.1.43 // indirect 62 | github.com/mitchellh/go-homedir v1.1.0 // indirect 63 | github.com/mitchellh/hashstructure v1.1.0 // indirect 64 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 65 | github.com/modern-go/reflect2 v1.0.2 // indirect 66 | github.com/nxadm/tail v1.4.8 // indirect 67 | github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect 68 | github.com/patrickmn/go-cache v2.1.0+incompatible // indirect 69 | github.com/pelletier/go-toml/v2 v2.0.8 // indirect 70 | github.com/pierrec/lz4 v2.6.1+incompatible // indirect 71 | github.com/pkg/errors v0.9.1 // indirect 72 | github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect 73 | github.com/rogpeppe/go-internal v1.11.0 // indirect 74 | github.com/russross/blackfriday/v2 v2.0.1 // indirect 75 | github.com/sergi/go-diff v1.1.0 // indirect 76 | github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect 77 | github.com/stretchr/testify v1.8.4 // indirect 78 | github.com/twitchyliquid64/golang-asm v0.15.1 // indirect 79 | github.com/ugorji/go/codec v1.2.11 // indirect 80 | github.com/urfave/cli/v2 v2.3.0 // indirect 81 | github.com/xanzy/ssh-agent v0.3.0 // indirect 82 | go.etcd.io/etcd/api/v3 v3.5.2 // indirect 83 | go.etcd.io/etcd/client/pkg/v3 v3.5.2 // indirect 84 | go.etcd.io/etcd/client/v3 v3.5.2 // indirect 85 | go.uber.org/atomic v1.7.0 // indirect 86 | go.uber.org/multierr v1.6.0 // indirect 87 | go.uber.org/zap v1.17.0 // indirect 88 | golang.org/x/arch v0.3.0 // indirect 89 | golang.org/x/crypto v0.9.0 // indirect 90 | golang.org/x/mod v0.9.0 // indirect 91 | golang.org/x/net v0.10.0 // indirect 92 | golang.org/x/sync v0.1.0 // indirect 93 | golang.org/x/sys v0.12.0 // indirect 94 | golang.org/x/text v0.9.0 // indirect 95 | golang.org/x/tools v0.7.0 // indirect 96 | google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect 97 | google.golang.org/grpc v1.53.0 // indirect 98 | google.golang.org/grpc/examples v0.0.0-20211102180624-670c133e568e // indirect 99 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect 100 | gopkg.in/warnings.v0 v0.1.2 // indirect 101 | gopkg.in/yaml.v3 v3.0.1 // indirect 102 | ) 103 | -------------------------------------------------------------------------------- /v4/stream/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "io" 6 | "math/rand" 7 | "time" 8 | 9 | "github.com/go-micro/plugins/v4/client/grpc" 10 | pb "github.com/xpunch/go-micro-example/v4/proto" 11 | "go-micro.dev/v4" 12 | "go-micro.dev/v4/logger" 13 | ) 14 | 15 | func main() { 16 | srv := micro.NewService( 17 | micro.Client(grpc.NewClient()), 18 | micro.Name("stream-client-v4"), 19 | ) 20 | srv.Init() 21 | client := pb.NewRouteGuideService("stream-server-v4", srv.Client()) 22 | 23 | // Looking for a valid feature 24 | printFeature(client, &pb.Point{Latitude: 409146138, Longitude: -746188906}) 25 | // Feature missing. 26 | printFeature(client, &pb.Point{Latitude: 0, Longitude: 0}) 27 | 28 | // Looking for features between 40, -75 and 42, -73. 29 | printFeatures(client, &pb.Rectangle{ 30 | Lo: &pb.Point{Latitude: 400000000, Longitude: -750000000}, 31 | Hi: &pb.Point{Latitude: 420000000, Longitude: -730000000}, 32 | }) 33 | 34 | // RecordRoute 35 | runRecordRoute(client) 36 | 37 | // RouteChat 38 | runRouteChat(client) 39 | } 40 | 41 | // printFeature gets the feature for the given point. 42 | func printFeature(client pb.RouteGuideService, point *pb.Point) { 43 | logger.Info("Getting feature for point (%d, %d)", point.Latitude, point.Longitude) 44 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 45 | defer cancel() 46 | feature, err := client.GetFeature(ctx, point) 47 | if err != nil { 48 | logger.Fatal(err) 49 | } 50 | logger.Info(feature) 51 | } 52 | 53 | // printFeatures lists all the features within the given bounding Rectangle. 54 | func printFeatures(client pb.RouteGuideService, rect *pb.Rectangle) { 55 | logger.Infof("Looking for features within %v", rect) 56 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 57 | defer cancel() 58 | stream, err := client.ListFeatures(ctx, rect) 59 | if err != nil { 60 | logger.Fatal(err) 61 | } 62 | for { 63 | feature, err := stream.Recv() 64 | if err == io.EOF { 65 | break 66 | } 67 | if err != nil { 68 | logger.Fatal(err) 69 | } 70 | logger.Infof("Feature: name: %q, point:(%v, %v)", feature.GetName(), 71 | feature.GetLocation().GetLatitude(), feature.GetLocation().GetLongitude()) 72 | } 73 | } 74 | 75 | // runRecordRoute sends a sequence of points to server and expects to get a RouteSummary from server. 76 | func runRecordRoute(client pb.RouteGuideService) { 77 | // Create a random number of random points 78 | r := rand.New(rand.NewSource(time.Now().UnixNano())) 79 | pointCount := int(r.Int31n(100)) + 2 // Traverse at least two points 80 | var points []*pb.Point 81 | for i := 0; i < pointCount; i++ { 82 | points = append(points, randomPoint(r)) 83 | } 84 | logger.Infof("Traversing %d points.", len(points)) 85 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 86 | defer cancel() 87 | stream, err := client.RecordRoute(ctx) 88 | if err != nil { 89 | logger.Fatal(err) 90 | } 91 | // IMPORTANT: do not forgot to close stream 92 | defer stream.Close() 93 | for _, point := range points { 94 | if err := stream.Send(point); err != nil { 95 | logger.Fatal(err) 96 | } 97 | } 98 | if err := stream.CloseSend(); err != nil { 99 | logger.Fatal(err) 100 | } 101 | summary := pb.RouteSummary{} 102 | if err := stream.RecvMsg(&summary); err != nil { 103 | logger.Fatal(err) 104 | } 105 | logger.Infof("Route summary: %v", &summary) 106 | } 107 | 108 | // runRouteChat receives a sequence of route notes, while sending notes for various locations. 109 | func runRouteChat(client pb.RouteGuideService) { 110 | notes := []*pb.RouteNote{ 111 | {Location: &pb.Point{Latitude: 0, Longitude: 1}, Message: "First message"}, 112 | {Location: &pb.Point{Latitude: 0, Longitude: 2}, Message: "Second message"}, 113 | {Location: &pb.Point{Latitude: 0, Longitude: 3}, Message: "Third message"}, 114 | {Location: &pb.Point{Latitude: 0, Longitude: 1}, Message: "Fourth message"}, 115 | {Location: &pb.Point{Latitude: 0, Longitude: 2}, Message: "Fifth message"}, 116 | {Location: &pb.Point{Latitude: 0, Longitude: 3}, Message: "Sixth message"}, 117 | } 118 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 119 | defer cancel() 120 | stream, err := client.RouteChat(ctx) 121 | if err != nil { 122 | logger.Fatal(err) 123 | } 124 | // IMPORTANT: do not forgot to close stream 125 | defer stream.Close() 126 | waitc := make(chan struct{}) 127 | go func() { 128 | for { 129 | in, err := stream.Recv() 130 | if err == io.EOF { 131 | // read done. 132 | close(waitc) 133 | break 134 | } 135 | if err != nil { 136 | logger.Fatal(err) 137 | } 138 | logger.Infof("Got message %s at point(%d, %d)", in.Message, in.Location.Latitude, in.Location.Longitude) 139 | } 140 | }() 141 | for _, note := range notes { 142 | if err := stream.Send(note); err != nil { 143 | logger.Fatal(err) 144 | } 145 | } 146 | if err := stream.CloseSend(); err != nil { 147 | logger.Fatal(err) 148 | } 149 | <-waitc 150 | } 151 | 152 | func randomPoint(r *rand.Rand) *pb.Point { 153 | lat := (r.Int31n(180) - 90) * 1e7 154 | long := (r.Int31n(360) - 180) * 1e7 155 | return &pb.Point{Latitude: lat, Longitude: long} 156 | } 157 | -------------------------------------------------------------------------------- /v4/proto/message.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.26.0 4 | // protoc v3.20.0 5 | // source: proto/message.proto 6 | 7 | package proto 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type Message struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` 29 | Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` 30 | Timestamp int64 `protobuf:"varint,3,opt,name=timestamp,proto3" json:"timestamp,omitempty"` 31 | } 32 | 33 | func (x *Message) Reset() { 34 | *x = Message{} 35 | if protoimpl.UnsafeEnabled { 36 | mi := &file_proto_message_proto_msgTypes[0] 37 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 38 | ms.StoreMessageInfo(mi) 39 | } 40 | } 41 | 42 | func (x *Message) String() string { 43 | return protoimpl.X.MessageStringOf(x) 44 | } 45 | 46 | func (*Message) ProtoMessage() {} 47 | 48 | func (x *Message) ProtoReflect() protoreflect.Message { 49 | mi := &file_proto_message_proto_msgTypes[0] 50 | if protoimpl.UnsafeEnabled && x != nil { 51 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 52 | if ms.LoadMessageInfo() == nil { 53 | ms.StoreMessageInfo(mi) 54 | } 55 | return ms 56 | } 57 | return mi.MessageOf(x) 58 | } 59 | 60 | // Deprecated: Use Message.ProtoReflect.Descriptor instead. 61 | func (*Message) Descriptor() ([]byte, []int) { 62 | return file_proto_message_proto_rawDescGZIP(), []int{0} 63 | } 64 | 65 | func (x *Message) GetId() string { 66 | if x != nil { 67 | return x.Id 68 | } 69 | return "" 70 | } 71 | 72 | func (x *Message) GetMessage() string { 73 | if x != nil { 74 | return x.Message 75 | } 76 | return "" 77 | } 78 | 79 | func (x *Message) GetTimestamp() int64 { 80 | if x != nil { 81 | return x.Timestamp 82 | } 83 | return 0 84 | } 85 | 86 | var File_proto_message_proto protoreflect.FileDescriptor 87 | 88 | var file_proto_message_proto_rawDesc = []byte{ 89 | 0x0a, 0x13, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x2e, 90 | 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x51, 0x0a, 0x07, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 91 | 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 92 | 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 93 | 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 94 | 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 95 | 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 96 | 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 97 | } 98 | 99 | var ( 100 | file_proto_message_proto_rawDescOnce sync.Once 101 | file_proto_message_proto_rawDescData = file_proto_message_proto_rawDesc 102 | ) 103 | 104 | func file_proto_message_proto_rawDescGZIP() []byte { 105 | file_proto_message_proto_rawDescOnce.Do(func() { 106 | file_proto_message_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_message_proto_rawDescData) 107 | }) 108 | return file_proto_message_proto_rawDescData 109 | } 110 | 111 | var file_proto_message_proto_msgTypes = make([]protoimpl.MessageInfo, 1) 112 | var file_proto_message_proto_goTypes = []interface{}{ 113 | (*Message)(nil), // 0: Message 114 | } 115 | var file_proto_message_proto_depIdxs = []int32{ 116 | 0, // [0:0] is the sub-list for method output_type 117 | 0, // [0:0] is the sub-list for method input_type 118 | 0, // [0:0] is the sub-list for extension type_name 119 | 0, // [0:0] is the sub-list for extension extendee 120 | 0, // [0:0] is the sub-list for field type_name 121 | } 122 | 123 | func init() { file_proto_message_proto_init() } 124 | func file_proto_message_proto_init() { 125 | if File_proto_message_proto != nil { 126 | return 127 | } 128 | if !protoimpl.UnsafeEnabled { 129 | file_proto_message_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 130 | switch v := v.(*Message); i { 131 | case 0: 132 | return &v.state 133 | case 1: 134 | return &v.sizeCache 135 | case 2: 136 | return &v.unknownFields 137 | default: 138 | return nil 139 | } 140 | } 141 | } 142 | type x struct{} 143 | out := protoimpl.TypeBuilder{ 144 | File: protoimpl.DescBuilder{ 145 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 146 | RawDescriptor: file_proto_message_proto_rawDesc, 147 | NumEnums: 0, 148 | NumMessages: 1, 149 | NumExtensions: 0, 150 | NumServices: 0, 151 | }, 152 | GoTypes: file_proto_message_proto_goTypes, 153 | DependencyIndexes: file_proto_message_proto_depIdxs, 154 | MessageInfos: file_proto_message_proto_msgTypes, 155 | }.Build() 156 | File_proto_message_proto = out.File 157 | file_proto_message_proto_rawDesc = nil 158 | file_proto_message_proto_goTypes = nil 159 | file_proto_message_proto_depIdxs = nil 160 | } 161 | -------------------------------------------------------------------------------- /v3/stream/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "io" 6 | "math/rand" 7 | "time" 8 | 9 | "github.com/asim/go-micro/plugins/client/grpc/v3" 10 | "github.com/asim/go-micro/v3" 11 | "github.com/asim/go-micro/v3/logger" 12 | pb "github.com/xpunch/go-micro-example/v3/stream/proto" 13 | ) 14 | 15 | // INT32_MAX used to present invalid point 16 | const INT32_MAX = int32(^uint32(0) >> 1) 17 | 18 | func main() { 19 | srv := micro.NewService( 20 | micro.Client(grpc.NewClient()), 21 | micro.Name("stream-client"), 22 | ) 23 | srv.Init() 24 | client := pb.NewRouteGuideService("stream-server", srv.Client()) 25 | 26 | // Looking for a valid feature 27 | printFeature(client, &pb.Point{Latitude: 409146138, Longitude: -746188906}) 28 | // Feature missing. 29 | printFeature(client, &pb.Point{Latitude: 0, Longitude: 0}) 30 | 31 | // Looking for features between 40, -75 and 42, -73. 32 | printFeatures(client, &pb.Rectangle{ 33 | Lo: &pb.Point{Latitude: 400000000, Longitude: -750000000}, 34 | Hi: &pb.Point{Latitude: 420000000, Longitude: -730000000}, 35 | }) 36 | 37 | // RecordRoute 38 | runRecordRoute(client) 39 | 40 | // RouteChat 41 | runRouteChat(client) 42 | } 43 | 44 | // printFeature gets the feature for the given point. 45 | func printFeature(client pb.RouteGuideService, point *pb.Point) { 46 | logger.Info("Getting feature for point (%d, %d)", point.Latitude, point.Longitude) 47 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 48 | defer cancel() 49 | feature, err := client.GetFeature(ctx, point) 50 | if err != nil { 51 | logger.Fatal(err) 52 | } 53 | logger.Info(feature) 54 | } 55 | 56 | // printFeatures lists all the features within the given bounding Rectangle. 57 | func printFeatures(client pb.RouteGuideService, rect *pb.Rectangle) { 58 | logger.Infof("Looking for features within %v", rect) 59 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 60 | defer cancel() 61 | stream, err := client.ListFeatures(ctx, rect) 62 | if err != nil { 63 | logger.Fatal(err) 64 | } 65 | for { 66 | feature, err := stream.Recv() 67 | if err == io.EOF { 68 | break 69 | } 70 | if err != nil { 71 | logger.Fatal(err) 72 | } 73 | logger.Infof("Feature: name: %q, point:(%v, %v)", feature.GetName(), 74 | feature.GetLocation().GetLatitude(), feature.GetLocation().GetLongitude()) 75 | } 76 | } 77 | 78 | // runRecordRoute sends a sequence of points to server and expects to get a RouteSummary from server. 79 | func runRecordRoute(client pb.RouteGuideService) { 80 | // Create a random number of random points 81 | r := rand.New(rand.NewSource(time.Now().UnixNano())) 82 | pointCount := int(r.Int31n(100)) + 2 // Traverse at least two points 83 | var points []*pb.Point 84 | for i := 0; i < pointCount; i++ { 85 | points = append(points, randomPoint(r)) 86 | } 87 | logger.Infof("Traversing %d points.", len(points)) 88 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 89 | defer cancel() 90 | stream, err := client.RecordRoute(ctx) 91 | if err != nil { 92 | logger.Fatal(err) 93 | } 94 | // IMPORTANT: do not forgot to close stream 95 | defer stream.Close() 96 | for _, point := range points { 97 | if err := stream.Send(point); err != nil { 98 | logger.Fatal(err) 99 | } 100 | } 101 | // TODO: should support client.SendClose() 102 | // https://github.com/asim/go-micro/issues/2212 103 | // used to present stream.CloseAndRecv() in grpc 104 | if err := stream.Send(&pb.Point{Latitude: INT32_MAX, Longitude: INT32_MAX}); err != nil { 105 | logger.Fatal(err) 106 | } 107 | summary := pb.RouteSummary{} 108 | if err := stream.RecvMsg(&summary); err != nil { 109 | logger.Fatal(err) 110 | } 111 | logger.Infof("Route summary: %v", &summary) 112 | } 113 | 114 | // runRouteChat receives a sequence of route notes, while sending notes for various locations. 115 | func runRouteChat(client pb.RouteGuideService) { 116 | notes := []*pb.RouteNote{ 117 | {Location: &pb.Point{Latitude: 0, Longitude: 1}, Message: "First message"}, 118 | {Location: &pb.Point{Latitude: 0, Longitude: 2}, Message: "Second message"}, 119 | {Location: &pb.Point{Latitude: 0, Longitude: 3}, Message: "Third message"}, 120 | {Location: &pb.Point{Latitude: 0, Longitude: 1}, Message: "Fourth message"}, 121 | {Location: &pb.Point{Latitude: 0, Longitude: 2}, Message: "Fifth message"}, 122 | {Location: &pb.Point{Latitude: 0, Longitude: 3}, Message: "Sixth message"}, 123 | } 124 | ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) 125 | defer cancel() 126 | stream, err := client.RouteChat(ctx) 127 | if err != nil { 128 | logger.Fatal(err) 129 | } 130 | // IMPORTANT: do not forgot to close stream 131 | defer stream.Close() 132 | waitc := make(chan struct{}) 133 | go func() { 134 | for { 135 | in, err := stream.Recv() 136 | if err == io.EOF { 137 | // read done. 138 | close(waitc) 139 | break 140 | } 141 | if err != nil { 142 | logger.Fatal(err) 143 | } 144 | logger.Infof("Got message %s at point(%d, %d)", in.Message, in.Location.Latitude, in.Location.Longitude) 145 | } 146 | }() 147 | for _, note := range notes { 148 | if err := stream.Send(note); err != nil { 149 | logger.Fatal(err) 150 | } 151 | } 152 | // TODO: should support client.SendClose() 153 | // https://github.com/asim/go-micro/issues/2212 154 | if err := stream.Send(&pb.RouteNote{}); err != nil { 155 | logger.Fatal(err) 156 | } 157 | <-waitc 158 | } 159 | 160 | func randomPoint(r *rand.Rand) *pb.Point { 161 | lat := (r.Int31n(180) - 90) * 1e7 162 | long := (r.Int31n(360) - 180) * 1e7 163 | return &pb.Point{Latitude: lat, Longitude: long} 164 | } 165 | -------------------------------------------------------------------------------- /v4/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/xpunch/go-micro-example/v4 2 | 3 | go 1.21.1 4 | 5 | require ( 6 | github.com/gin-gonic/gin v1.9.1 7 | github.com/go-micro/plugins/v4/broker/kafka v1.2.0 8 | github.com/go-micro/plugins/v4/broker/mqtt v1.2.0 9 | github.com/go-micro/plugins/v4/client/grpc v1.1.0 10 | github.com/go-micro/plugins/v4/registry/etcd v1.2.0 11 | github.com/go-micro/plugins/v4/server/grpc v1.2.0 12 | github.com/go-micro/plugins/v4/server/http v1.2.2 13 | github.com/go-micro/plugins/v4/wrapper/breaker/hystrix v1.2.0 14 | github.com/go-micro/plugins/v4/wrapper/trace/opentelemetry v1.2.0 15 | github.com/go-micro/plugins/v4/wrapper/trace/opentracing v1.2.0 16 | github.com/google/uuid v1.3.0 17 | github.com/opentracing/opentracing-go v1.2.0 18 | github.com/uber/jaeger-client-go v2.30.0+incompatible 19 | go-micro.dev/v4 v4.10.2 20 | go.opentelemetry.io/otel v1.18.0 21 | go.opentelemetry.io/otel/exporters/jaeger v1.17.0 22 | go.opentelemetry.io/otel/sdk v1.18.0 23 | google.golang.org/protobuf v1.30.0 24 | ) 25 | 26 | require ( 27 | github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect 28 | github.com/Microsoft/go-winio v0.6.0 // indirect 29 | github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect 30 | github.com/Shopify/sarama v1.30.1 // indirect 31 | github.com/acomagu/bufpipe v1.0.3 // indirect 32 | github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 // indirect 33 | github.com/bitly/go-simplejson v0.5.0 // indirect 34 | github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect 35 | github.com/bytedance/sonic v1.9.1 // indirect 36 | github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect 37 | github.com/coreos/go-semver v0.3.0 // indirect 38 | github.com/coreos/go-systemd/v22 v22.3.2 // indirect 39 | github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect 40 | github.com/davecgh/go-spew v1.1.1 // indirect 41 | github.com/eapache/go-resiliency v1.2.0 // indirect 42 | github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect 43 | github.com/eapache/queue v1.1.0 // indirect 44 | github.com/eclipse/paho.mqtt.golang v1.3.5 // indirect 45 | github.com/emirpasic/gods v1.12.0 // indirect 46 | github.com/evanphx/json-patch/v5 v5.5.0 // indirect 47 | github.com/felixge/httpsnoop v1.0.1 // indirect 48 | github.com/fsnotify/fsnotify v1.6.0 // indirect 49 | github.com/gabriel-vasile/mimetype v1.4.2 // indirect 50 | github.com/gin-contrib/sse v0.1.0 // indirect 51 | github.com/go-acme/lego/v4 v4.4.0 // indirect 52 | github.com/go-git/gcfg v1.5.0 // indirect 53 | github.com/go-git/go-billy/v5 v5.3.1 // indirect 54 | github.com/go-git/go-git/v5 v5.4.2 // indirect 55 | github.com/go-logr/logr v1.2.4 // indirect 56 | github.com/go-logr/stdr v1.2.2 // indirect 57 | github.com/go-playground/locales v0.14.1 // indirect 58 | github.com/go-playground/universal-translator v0.18.1 // indirect 59 | github.com/go-playground/validator/v10 v10.14.0 // indirect 60 | github.com/gobwas/httphead v0.1.0 // indirect 61 | github.com/gobwas/pool v0.2.1 // indirect 62 | github.com/gobwas/ws v1.0.4 // indirect 63 | github.com/goccy/go-json v0.10.2 // indirect 64 | github.com/gogo/protobuf v1.3.2 // indirect 65 | github.com/golang/protobuf v1.5.2 // indirect 66 | github.com/golang/snappy v0.0.4 // indirect 67 | github.com/gorilla/handlers v1.5.1 // indirect 68 | github.com/gorilla/websocket v1.4.2 // indirect 69 | github.com/hashicorp/go-uuid v1.0.2 // indirect 70 | github.com/imdario/mergo v0.3.12 // indirect 71 | github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect 72 | github.com/jcmturner/aescts/v2 v2.0.0 // indirect 73 | github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect 74 | github.com/jcmturner/gofork v1.0.0 // indirect 75 | github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect 76 | github.com/jcmturner/rpc/v2 v2.0.3 // indirect 77 | github.com/json-iterator/go v1.1.12 // indirect 78 | github.com/kevinburke/ssh_config v0.0.0-20201106050909-4977a11b4351 // indirect 79 | github.com/klauspost/compress v1.15.9 // indirect 80 | github.com/klauspost/cpuid/v2 v2.2.4 // indirect 81 | github.com/leodido/go-urn v1.2.4 // indirect 82 | github.com/mattn/go-isatty v0.0.19 // indirect 83 | github.com/miekg/dns v1.1.43 // indirect 84 | github.com/mitchellh/go-homedir v1.1.0 // indirect 85 | github.com/mitchellh/hashstructure v1.1.0 // indirect 86 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 87 | github.com/modern-go/reflect2 v1.0.2 // indirect 88 | github.com/nxadm/tail v1.4.8 // indirect 89 | github.com/oxtoacart/bpool v0.0.0-20190530202638-03653db5a59c // indirect 90 | github.com/patrickmn/go-cache v2.1.0+incompatible // indirect 91 | github.com/pelletier/go-toml/v2 v2.0.8 // indirect 92 | github.com/pierrec/lz4 v2.6.1+incompatible // indirect 93 | github.com/pkg/errors v0.9.1 // indirect 94 | github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect 95 | github.com/rogpeppe/go-internal v1.11.0 // indirect 96 | github.com/russross/blackfriday/v2 v2.0.1 // indirect 97 | github.com/sergi/go-diff v1.1.0 // indirect 98 | github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect 99 | github.com/twitchyliquid64/golang-asm v0.15.1 // indirect 100 | github.com/uber/jaeger-lib v2.4.1+incompatible // indirect 101 | github.com/ugorji/go/codec v1.2.11 // indirect 102 | github.com/urfave/cli/v2 v2.3.0 // indirect 103 | github.com/xanzy/ssh-agent v0.3.0 // indirect 104 | go.etcd.io/etcd/api/v3 v3.5.2 // indirect 105 | go.etcd.io/etcd/client/pkg/v3 v3.5.2 // indirect 106 | go.etcd.io/etcd/client/v3 v3.5.2 // indirect 107 | go.opentelemetry.io/otel/metric v1.18.0 // indirect 108 | go.opentelemetry.io/otel/trace v1.18.0 // indirect 109 | go.uber.org/atomic v1.7.0 // indirect 110 | go.uber.org/multierr v1.6.0 // indirect 111 | go.uber.org/zap v1.17.0 // indirect 112 | golang.org/x/arch v0.3.0 // indirect 113 | golang.org/x/crypto v0.9.0 // indirect 114 | golang.org/x/mod v0.9.0 // indirect 115 | golang.org/x/net v0.10.0 // indirect 116 | golang.org/x/sync v0.1.0 // indirect 117 | golang.org/x/sys v0.12.0 // indirect 118 | golang.org/x/text v0.9.0 // indirect 119 | golang.org/x/tools v0.7.0 // indirect 120 | google.golang.org/genproto v0.0.0-20230306155012-7f2fa6fef1f4 // indirect 121 | google.golang.org/grpc v1.53.0 // indirect 122 | gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect 123 | gopkg.in/warnings.v0 v0.1.2 // indirect 124 | gopkg.in/yaml.v3 v3.0.1 // indirect 125 | ) 126 | -------------------------------------------------------------------------------- /v4/proto/helloworld.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.26.0 4 | // protoc v3.20.0 5 | // source: proto/helloworld.proto 6 | 7 | package proto 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type Request struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` 29 | } 30 | 31 | func (x *Request) Reset() { 32 | *x = Request{} 33 | if protoimpl.UnsafeEnabled { 34 | mi := &file_proto_helloworld_proto_msgTypes[0] 35 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 36 | ms.StoreMessageInfo(mi) 37 | } 38 | } 39 | 40 | func (x *Request) String() string { 41 | return protoimpl.X.MessageStringOf(x) 42 | } 43 | 44 | func (*Request) ProtoMessage() {} 45 | 46 | func (x *Request) ProtoReflect() protoreflect.Message { 47 | mi := &file_proto_helloworld_proto_msgTypes[0] 48 | if protoimpl.UnsafeEnabled && x != nil { 49 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 50 | if ms.LoadMessageInfo() == nil { 51 | ms.StoreMessageInfo(mi) 52 | } 53 | return ms 54 | } 55 | return mi.MessageOf(x) 56 | } 57 | 58 | // Deprecated: Use Request.ProtoReflect.Descriptor instead. 59 | func (*Request) Descriptor() ([]byte, []int) { 60 | return file_proto_helloworld_proto_rawDescGZIP(), []int{0} 61 | } 62 | 63 | func (x *Request) GetName() string { 64 | if x != nil { 65 | return x.Name 66 | } 67 | return "" 68 | } 69 | 70 | type Response struct { 71 | state protoimpl.MessageState 72 | sizeCache protoimpl.SizeCache 73 | unknownFields protoimpl.UnknownFields 74 | 75 | Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` 76 | } 77 | 78 | func (x *Response) Reset() { 79 | *x = Response{} 80 | if protoimpl.UnsafeEnabled { 81 | mi := &file_proto_helloworld_proto_msgTypes[1] 82 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 83 | ms.StoreMessageInfo(mi) 84 | } 85 | } 86 | 87 | func (x *Response) String() string { 88 | return protoimpl.X.MessageStringOf(x) 89 | } 90 | 91 | func (*Response) ProtoMessage() {} 92 | 93 | func (x *Response) ProtoReflect() protoreflect.Message { 94 | mi := &file_proto_helloworld_proto_msgTypes[1] 95 | if protoimpl.UnsafeEnabled && x != nil { 96 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 97 | if ms.LoadMessageInfo() == nil { 98 | ms.StoreMessageInfo(mi) 99 | } 100 | return ms 101 | } 102 | return mi.MessageOf(x) 103 | } 104 | 105 | // Deprecated: Use Response.ProtoReflect.Descriptor instead. 106 | func (*Response) Descriptor() ([]byte, []int) { 107 | return file_proto_helloworld_proto_rawDescGZIP(), []int{1} 108 | } 109 | 110 | func (x *Response) GetMessage() string { 111 | if x != nil { 112 | return x.Message 113 | } 114 | return "" 115 | } 116 | 117 | var File_proto_helloworld_proto protoreflect.FileDescriptor 118 | 119 | var file_proto_helloworld_proto_rawDesc = []byte{ 120 | 0x0a, 0x16, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 121 | 0x6c, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x1d, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 122 | 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 123 | 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x22, 0x24, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 124 | 0x6e, 0x73, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 125 | 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x2b, 0x0a, 126 | 0x0a, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x12, 0x1d, 0x0a, 0x04, 0x43, 127 | 0x61, 0x6c, 0x6c, 0x12, 0x08, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x09, 0x2e, 128 | 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 129 | 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 130 | } 131 | 132 | var ( 133 | file_proto_helloworld_proto_rawDescOnce sync.Once 134 | file_proto_helloworld_proto_rawDescData = file_proto_helloworld_proto_rawDesc 135 | ) 136 | 137 | func file_proto_helloworld_proto_rawDescGZIP() []byte { 138 | file_proto_helloworld_proto_rawDescOnce.Do(func() { 139 | file_proto_helloworld_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_helloworld_proto_rawDescData) 140 | }) 141 | return file_proto_helloworld_proto_rawDescData 142 | } 143 | 144 | var file_proto_helloworld_proto_msgTypes = make([]protoimpl.MessageInfo, 2) 145 | var file_proto_helloworld_proto_goTypes = []interface{}{ 146 | (*Request)(nil), // 0: Request 147 | (*Response)(nil), // 1: Response 148 | } 149 | var file_proto_helloworld_proto_depIdxs = []int32{ 150 | 0, // 0: Helloworld.Call:input_type -> Request 151 | 1, // 1: Helloworld.Call:output_type -> Response 152 | 1, // [1:2] is the sub-list for method output_type 153 | 0, // [0:1] is the sub-list for method input_type 154 | 0, // [0:0] is the sub-list for extension type_name 155 | 0, // [0:0] is the sub-list for extension extendee 156 | 0, // [0:0] is the sub-list for field type_name 157 | } 158 | 159 | func init() { file_proto_helloworld_proto_init() } 160 | func file_proto_helloworld_proto_init() { 161 | if File_proto_helloworld_proto != nil { 162 | return 163 | } 164 | if !protoimpl.UnsafeEnabled { 165 | file_proto_helloworld_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 166 | switch v := v.(*Request); i { 167 | case 0: 168 | return &v.state 169 | case 1: 170 | return &v.sizeCache 171 | case 2: 172 | return &v.unknownFields 173 | default: 174 | return nil 175 | } 176 | } 177 | file_proto_helloworld_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 178 | switch v := v.(*Response); i { 179 | case 0: 180 | return &v.state 181 | case 1: 182 | return &v.sizeCache 183 | case 2: 184 | return &v.unknownFields 185 | default: 186 | return nil 187 | } 188 | } 189 | } 190 | type x struct{} 191 | out := protoimpl.TypeBuilder{ 192 | File: protoimpl.DescBuilder{ 193 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 194 | RawDescriptor: file_proto_helloworld_proto_rawDesc, 195 | NumEnums: 0, 196 | NumMessages: 2, 197 | NumExtensions: 0, 198 | NumServices: 1, 199 | }, 200 | GoTypes: file_proto_helloworld_proto_goTypes, 201 | DependencyIndexes: file_proto_helloworld_proto_depIdxs, 202 | MessageInfos: file_proto_helloworld_proto_msgTypes, 203 | }.Build() 204 | File_proto_helloworld_proto = out.File 205 | file_proto_helloworld_proto_rawDesc = nil 206 | file_proto_helloworld_proto_goTypes = nil 207 | file_proto_helloworld_proto_depIdxs = nil 208 | } 209 | -------------------------------------------------------------------------------- /v3/helloworld/proto/helloworld.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.28.1 4 | // protoc v3.20.0 5 | // source: helloworld/proto/helloworld.proto 6 | 7 | package proto 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type Request struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` 29 | } 30 | 31 | func (x *Request) Reset() { 32 | *x = Request{} 33 | if protoimpl.UnsafeEnabled { 34 | mi := &file_helloworld_proto_helloworld_proto_msgTypes[0] 35 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 36 | ms.StoreMessageInfo(mi) 37 | } 38 | } 39 | 40 | func (x *Request) String() string { 41 | return protoimpl.X.MessageStringOf(x) 42 | } 43 | 44 | func (*Request) ProtoMessage() {} 45 | 46 | func (x *Request) ProtoReflect() protoreflect.Message { 47 | mi := &file_helloworld_proto_helloworld_proto_msgTypes[0] 48 | if protoimpl.UnsafeEnabled && x != nil { 49 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 50 | if ms.LoadMessageInfo() == nil { 51 | ms.StoreMessageInfo(mi) 52 | } 53 | return ms 54 | } 55 | return mi.MessageOf(x) 56 | } 57 | 58 | // Deprecated: Use Request.ProtoReflect.Descriptor instead. 59 | func (*Request) Descriptor() ([]byte, []int) { 60 | return file_helloworld_proto_helloworld_proto_rawDescGZIP(), []int{0} 61 | } 62 | 63 | func (x *Request) GetName() string { 64 | if x != nil { 65 | return x.Name 66 | } 67 | return "" 68 | } 69 | 70 | type Response struct { 71 | state protoimpl.MessageState 72 | sizeCache protoimpl.SizeCache 73 | unknownFields protoimpl.UnknownFields 74 | 75 | Message string `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"` 76 | } 77 | 78 | func (x *Response) Reset() { 79 | *x = Response{} 80 | if protoimpl.UnsafeEnabled { 81 | mi := &file_helloworld_proto_helloworld_proto_msgTypes[1] 82 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 83 | ms.StoreMessageInfo(mi) 84 | } 85 | } 86 | 87 | func (x *Response) String() string { 88 | return protoimpl.X.MessageStringOf(x) 89 | } 90 | 91 | func (*Response) ProtoMessage() {} 92 | 93 | func (x *Response) ProtoReflect() protoreflect.Message { 94 | mi := &file_helloworld_proto_helloworld_proto_msgTypes[1] 95 | if protoimpl.UnsafeEnabled && x != nil { 96 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 97 | if ms.LoadMessageInfo() == nil { 98 | ms.StoreMessageInfo(mi) 99 | } 100 | return ms 101 | } 102 | return mi.MessageOf(x) 103 | } 104 | 105 | // Deprecated: Use Response.ProtoReflect.Descriptor instead. 106 | func (*Response) Descriptor() ([]byte, []int) { 107 | return file_helloworld_proto_helloworld_proto_rawDescGZIP(), []int{1} 108 | } 109 | 110 | func (x *Response) GetMessage() string { 111 | if x != nil { 112 | return x.Message 113 | } 114 | return "" 115 | } 116 | 117 | var File_helloworld_proto_helloworld_proto protoreflect.FileDescriptor 118 | 119 | var file_helloworld_proto_helloworld_proto_rawDesc = []byte{ 120 | 0x0a, 0x21, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2f, 0x70, 0x72, 0x6f, 121 | 0x74, 0x6f, 0x2f, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x2e, 0x70, 0x72, 122 | 0x6f, 0x74, 0x6f, 0x22, 0x1d, 0x0a, 0x07, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 123 | 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 124 | 0x6d, 0x65, 0x22, 0x24, 0x0a, 0x08, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x18, 125 | 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 126 | 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x32, 0x2b, 0x0a, 0x0a, 0x48, 0x65, 0x6c, 0x6c, 127 | 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x12, 0x1d, 0x0a, 0x04, 0x43, 0x61, 0x6c, 0x6c, 0x12, 0x08, 128 | 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x09, 0x2e, 0x52, 0x65, 0x73, 0x70, 0x6f, 129 | 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 130 | 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 131 | } 132 | 133 | var ( 134 | file_helloworld_proto_helloworld_proto_rawDescOnce sync.Once 135 | file_helloworld_proto_helloworld_proto_rawDescData = file_helloworld_proto_helloworld_proto_rawDesc 136 | ) 137 | 138 | func file_helloworld_proto_helloworld_proto_rawDescGZIP() []byte { 139 | file_helloworld_proto_helloworld_proto_rawDescOnce.Do(func() { 140 | file_helloworld_proto_helloworld_proto_rawDescData = protoimpl.X.CompressGZIP(file_helloworld_proto_helloworld_proto_rawDescData) 141 | }) 142 | return file_helloworld_proto_helloworld_proto_rawDescData 143 | } 144 | 145 | var file_helloworld_proto_helloworld_proto_msgTypes = make([]protoimpl.MessageInfo, 2) 146 | var file_helloworld_proto_helloworld_proto_goTypes = []interface{}{ 147 | (*Request)(nil), // 0: Request 148 | (*Response)(nil), // 1: Response 149 | } 150 | var file_helloworld_proto_helloworld_proto_depIdxs = []int32{ 151 | 0, // 0: Helloworld.Call:input_type -> Request 152 | 1, // 1: Helloworld.Call:output_type -> Response 153 | 1, // [1:2] is the sub-list for method output_type 154 | 0, // [0:1] is the sub-list for method input_type 155 | 0, // [0:0] is the sub-list for extension type_name 156 | 0, // [0:0] is the sub-list for extension extendee 157 | 0, // [0:0] is the sub-list for field type_name 158 | } 159 | 160 | func init() { file_helloworld_proto_helloworld_proto_init() } 161 | func file_helloworld_proto_helloworld_proto_init() { 162 | if File_helloworld_proto_helloworld_proto != nil { 163 | return 164 | } 165 | if !protoimpl.UnsafeEnabled { 166 | file_helloworld_proto_helloworld_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 167 | switch v := v.(*Request); i { 168 | case 0: 169 | return &v.state 170 | case 1: 171 | return &v.sizeCache 172 | case 2: 173 | return &v.unknownFields 174 | default: 175 | return nil 176 | } 177 | } 178 | file_helloworld_proto_helloworld_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 179 | switch v := v.(*Response); i { 180 | case 0: 181 | return &v.state 182 | case 1: 183 | return &v.sizeCache 184 | case 2: 185 | return &v.unknownFields 186 | default: 187 | return nil 188 | } 189 | } 190 | } 191 | type x struct{} 192 | out := protoimpl.TypeBuilder{ 193 | File: protoimpl.DescBuilder{ 194 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 195 | RawDescriptor: file_helloworld_proto_helloworld_proto_rawDesc, 196 | NumEnums: 0, 197 | NumMessages: 2, 198 | NumExtensions: 0, 199 | NumServices: 1, 200 | }, 201 | GoTypes: file_helloworld_proto_helloworld_proto_goTypes, 202 | DependencyIndexes: file_helloworld_proto_helloworld_proto_depIdxs, 203 | MessageInfos: file_helloworld_proto_helloworld_proto_msgTypes, 204 | }.Build() 205 | File_helloworld_proto_helloworld_proto = out.File 206 | file_helloworld_proto_helloworld_proto_rawDesc = nil 207 | file_helloworld_proto_helloworld_proto_goTypes = nil 208 | file_helloworld_proto_helloworld_proto_depIdxs = nil 209 | } 210 | -------------------------------------------------------------------------------- /v4/proto/statistics.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.26.0 4 | // protoc v3.20.0 5 | // source: proto/statistics.proto 6 | 7 | package proto 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type StatisticsRequest struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | Method *string `protobuf:"bytes,1,opt,name=method,proto3,oneof" json:"method,omitempty"` 29 | } 30 | 31 | func (x *StatisticsRequest) Reset() { 32 | *x = StatisticsRequest{} 33 | if protoimpl.UnsafeEnabled { 34 | mi := &file_proto_statistics_proto_msgTypes[0] 35 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 36 | ms.StoreMessageInfo(mi) 37 | } 38 | } 39 | 40 | func (x *StatisticsRequest) String() string { 41 | return protoimpl.X.MessageStringOf(x) 42 | } 43 | 44 | func (*StatisticsRequest) ProtoMessage() {} 45 | 46 | func (x *StatisticsRequest) ProtoReflect() protoreflect.Message { 47 | mi := &file_proto_statistics_proto_msgTypes[0] 48 | if protoimpl.UnsafeEnabled && x != nil { 49 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 50 | if ms.LoadMessageInfo() == nil { 51 | ms.StoreMessageInfo(mi) 52 | } 53 | return ms 54 | } 55 | return mi.MessageOf(x) 56 | } 57 | 58 | // Deprecated: Use StatisticsRequest.ProtoReflect.Descriptor instead. 59 | func (*StatisticsRequest) Descriptor() ([]byte, []int) { 60 | return file_proto_statistics_proto_rawDescGZIP(), []int{0} 61 | } 62 | 63 | func (x *StatisticsRequest) GetMethod() string { 64 | if x != nil && x.Method != nil { 65 | return *x.Method 66 | } 67 | return "" 68 | } 69 | 70 | type StatisticsReply struct { 71 | state protoimpl.MessageState 72 | sizeCache protoimpl.SizeCache 73 | unknownFields protoimpl.UnknownFields 74 | 75 | AccessCount int64 `protobuf:"varint,1,opt,name=access_count,json=accessCount,proto3" json:"access_count,omitempty"` 76 | } 77 | 78 | func (x *StatisticsReply) Reset() { 79 | *x = StatisticsReply{} 80 | if protoimpl.UnsafeEnabled { 81 | mi := &file_proto_statistics_proto_msgTypes[1] 82 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 83 | ms.StoreMessageInfo(mi) 84 | } 85 | } 86 | 87 | func (x *StatisticsReply) String() string { 88 | return protoimpl.X.MessageStringOf(x) 89 | } 90 | 91 | func (*StatisticsReply) ProtoMessage() {} 92 | 93 | func (x *StatisticsReply) ProtoReflect() protoreflect.Message { 94 | mi := &file_proto_statistics_proto_msgTypes[1] 95 | if protoimpl.UnsafeEnabled && x != nil { 96 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 97 | if ms.LoadMessageInfo() == nil { 98 | ms.StoreMessageInfo(mi) 99 | } 100 | return ms 101 | } 102 | return mi.MessageOf(x) 103 | } 104 | 105 | // Deprecated: Use StatisticsReply.ProtoReflect.Descriptor instead. 106 | func (*StatisticsReply) Descriptor() ([]byte, []int) { 107 | return file_proto_statistics_proto_rawDescGZIP(), []int{1} 108 | } 109 | 110 | func (x *StatisticsReply) GetAccessCount() int64 { 111 | if x != nil { 112 | return x.AccessCount 113 | } 114 | return 0 115 | } 116 | 117 | type AccessEvent struct { 118 | state protoimpl.MessageState 119 | sizeCache protoimpl.SizeCache 120 | unknownFields protoimpl.UnknownFields 121 | 122 | Status uint32 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` 123 | Method string `protobuf:"bytes,2,opt,name=method,proto3" json:"method,omitempty"` 124 | Path string `protobuf:"bytes,3,opt,name=path,proto3" json:"path,omitempty"` 125 | Ip string `protobuf:"bytes,4,opt,name=ip,proto3" json:"ip,omitempty"` 126 | Latency int64 `protobuf:"varint,5,opt,name=latency,proto3" json:"latency,omitempty"` 127 | Timestamp int64 `protobuf:"varint,6,opt,name=timestamp,proto3" json:"timestamp,omitempty"` 128 | } 129 | 130 | func (x *AccessEvent) Reset() { 131 | *x = AccessEvent{} 132 | if protoimpl.UnsafeEnabled { 133 | mi := &file_proto_statistics_proto_msgTypes[2] 134 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 135 | ms.StoreMessageInfo(mi) 136 | } 137 | } 138 | 139 | func (x *AccessEvent) String() string { 140 | return protoimpl.X.MessageStringOf(x) 141 | } 142 | 143 | func (*AccessEvent) ProtoMessage() {} 144 | 145 | func (x *AccessEvent) ProtoReflect() protoreflect.Message { 146 | mi := &file_proto_statistics_proto_msgTypes[2] 147 | if protoimpl.UnsafeEnabled && x != nil { 148 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 149 | if ms.LoadMessageInfo() == nil { 150 | ms.StoreMessageInfo(mi) 151 | } 152 | return ms 153 | } 154 | return mi.MessageOf(x) 155 | } 156 | 157 | // Deprecated: Use AccessEvent.ProtoReflect.Descriptor instead. 158 | func (*AccessEvent) Descriptor() ([]byte, []int) { 159 | return file_proto_statistics_proto_rawDescGZIP(), []int{2} 160 | } 161 | 162 | func (x *AccessEvent) GetStatus() uint32 { 163 | if x != nil { 164 | return x.Status 165 | } 166 | return 0 167 | } 168 | 169 | func (x *AccessEvent) GetMethod() string { 170 | if x != nil { 171 | return x.Method 172 | } 173 | return "" 174 | } 175 | 176 | func (x *AccessEvent) GetPath() string { 177 | if x != nil { 178 | return x.Path 179 | } 180 | return "" 181 | } 182 | 183 | func (x *AccessEvent) GetIp() string { 184 | if x != nil { 185 | return x.Ip 186 | } 187 | return "" 188 | } 189 | 190 | func (x *AccessEvent) GetLatency() int64 { 191 | if x != nil { 192 | return x.Latency 193 | } 194 | return 0 195 | } 196 | 197 | func (x *AccessEvent) GetTimestamp() int64 { 198 | if x != nil { 199 | return x.Timestamp 200 | } 201 | return 0 202 | } 203 | 204 | var File_proto_statistics_proto protoreflect.FileDescriptor 205 | 206 | var file_proto_statistics_proto_rawDesc = []byte{ 207 | 0x0a, 0x16, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 208 | 0x63, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3b, 0x0a, 0x11, 0x53, 0x74, 0x61, 0x74, 209 | 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 210 | 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 211 | 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x88, 0x01, 0x01, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x6d, 212 | 0x65, 0x74, 0x68, 0x6f, 0x64, 0x22, 0x34, 0x0a, 0x0f, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 213 | 0x69, 0x63, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x65, 214 | 0x73, 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 215 | 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0x99, 0x01, 0x0a, 0x0b, 216 | 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 217 | 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x73, 0x74, 0x61, 218 | 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 219 | 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x70, 220 | 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 221 | 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x70, 0x12, 222 | 0x18, 0x0a, 0x07, 0x6c, 0x61, 0x74, 0x65, 0x6e, 0x63, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 223 | 0x52, 0x07, 0x6c, 0x61, 0x74, 0x65, 0x6e, 0x63, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 224 | 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 225 | 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x32, 0x49, 0x0a, 0x11, 0x53, 0x74, 0x61, 0x74, 0x69, 226 | 0x73, 0x74, 0x69, 0x63, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x34, 0x0a, 0x0a, 227 | 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x12, 0x12, 0x2e, 0x53, 0x74, 0x61, 228 | 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 229 | 0x2e, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 230 | 0x22, 0x00, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 231 | 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 232 | } 233 | 234 | var ( 235 | file_proto_statistics_proto_rawDescOnce sync.Once 236 | file_proto_statistics_proto_rawDescData = file_proto_statistics_proto_rawDesc 237 | ) 238 | 239 | func file_proto_statistics_proto_rawDescGZIP() []byte { 240 | file_proto_statistics_proto_rawDescOnce.Do(func() { 241 | file_proto_statistics_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_statistics_proto_rawDescData) 242 | }) 243 | return file_proto_statistics_proto_rawDescData 244 | } 245 | 246 | var file_proto_statistics_proto_msgTypes = make([]protoimpl.MessageInfo, 3) 247 | var file_proto_statistics_proto_goTypes = []interface{}{ 248 | (*StatisticsRequest)(nil), // 0: StatisticsRequest 249 | (*StatisticsReply)(nil), // 1: StatisticsReply 250 | (*AccessEvent)(nil), // 2: AccessEvent 251 | } 252 | var file_proto_statistics_proto_depIdxs = []int32{ 253 | 0, // 0: StatisticsService.Statistics:input_type -> StatisticsRequest 254 | 1, // 1: StatisticsService.Statistics:output_type -> StatisticsReply 255 | 1, // [1:2] is the sub-list for method output_type 256 | 0, // [0:1] is the sub-list for method input_type 257 | 0, // [0:0] is the sub-list for extension type_name 258 | 0, // [0:0] is the sub-list for extension extendee 259 | 0, // [0:0] is the sub-list for field type_name 260 | } 261 | 262 | func init() { file_proto_statistics_proto_init() } 263 | func file_proto_statistics_proto_init() { 264 | if File_proto_statistics_proto != nil { 265 | return 266 | } 267 | if !protoimpl.UnsafeEnabled { 268 | file_proto_statistics_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 269 | switch v := v.(*StatisticsRequest); i { 270 | case 0: 271 | return &v.state 272 | case 1: 273 | return &v.sizeCache 274 | case 2: 275 | return &v.unknownFields 276 | default: 277 | return nil 278 | } 279 | } 280 | file_proto_statistics_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 281 | switch v := v.(*StatisticsReply); i { 282 | case 0: 283 | return &v.state 284 | case 1: 285 | return &v.sizeCache 286 | case 2: 287 | return &v.unknownFields 288 | default: 289 | return nil 290 | } 291 | } 292 | file_proto_statistics_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { 293 | switch v := v.(*AccessEvent); i { 294 | case 0: 295 | return &v.state 296 | case 1: 297 | return &v.sizeCache 298 | case 2: 299 | return &v.unknownFields 300 | default: 301 | return nil 302 | } 303 | } 304 | } 305 | file_proto_statistics_proto_msgTypes[0].OneofWrappers = []interface{}{} 306 | type x struct{} 307 | out := protoimpl.TypeBuilder{ 308 | File: protoimpl.DescBuilder{ 309 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 310 | RawDescriptor: file_proto_statistics_proto_rawDesc, 311 | NumEnums: 0, 312 | NumMessages: 3, 313 | NumExtensions: 0, 314 | NumServices: 1, 315 | }, 316 | GoTypes: file_proto_statistics_proto_goTypes, 317 | DependencyIndexes: file_proto_statistics_proto_depIdxs, 318 | MessageInfos: file_proto_statistics_proto_msgTypes, 319 | }.Build() 320 | File_proto_statistics_proto = out.File 321 | file_proto_statistics_proto_rawDesc = nil 322 | file_proto_statistics_proto_goTypes = nil 323 | file_proto_statistics_proto_depIdxs = nil 324 | } 325 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /v3/event/proto/statistics.pb.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-go. DO NOT EDIT. 2 | // versions: 3 | // protoc-gen-go v1.28.1 4 | // protoc v3.20.0 5 | // source: event/proto/statistics.proto 6 | 7 | package proto 8 | 9 | import ( 10 | protoreflect "google.golang.org/protobuf/reflect/protoreflect" 11 | protoimpl "google.golang.org/protobuf/runtime/protoimpl" 12 | reflect "reflect" 13 | sync "sync" 14 | ) 15 | 16 | const ( 17 | // Verify that this generated code is sufficiently up-to-date. 18 | _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) 19 | // Verify that runtime/protoimpl is sufficiently up-to-date. 20 | _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) 21 | ) 22 | 23 | type StatisticsRequest struct { 24 | state protoimpl.MessageState 25 | sizeCache protoimpl.SizeCache 26 | unknownFields protoimpl.UnknownFields 27 | 28 | Method *string `protobuf:"bytes,1,opt,name=method,proto3,oneof" json:"method,omitempty"` 29 | } 30 | 31 | func (x *StatisticsRequest) Reset() { 32 | *x = StatisticsRequest{} 33 | if protoimpl.UnsafeEnabled { 34 | mi := &file_event_proto_statistics_proto_msgTypes[0] 35 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 36 | ms.StoreMessageInfo(mi) 37 | } 38 | } 39 | 40 | func (x *StatisticsRequest) String() string { 41 | return protoimpl.X.MessageStringOf(x) 42 | } 43 | 44 | func (*StatisticsRequest) ProtoMessage() {} 45 | 46 | func (x *StatisticsRequest) ProtoReflect() protoreflect.Message { 47 | mi := &file_event_proto_statistics_proto_msgTypes[0] 48 | if protoimpl.UnsafeEnabled && x != nil { 49 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 50 | if ms.LoadMessageInfo() == nil { 51 | ms.StoreMessageInfo(mi) 52 | } 53 | return ms 54 | } 55 | return mi.MessageOf(x) 56 | } 57 | 58 | // Deprecated: Use StatisticsRequest.ProtoReflect.Descriptor instead. 59 | func (*StatisticsRequest) Descriptor() ([]byte, []int) { 60 | return file_event_proto_statistics_proto_rawDescGZIP(), []int{0} 61 | } 62 | 63 | func (x *StatisticsRequest) GetMethod() string { 64 | if x != nil && x.Method != nil { 65 | return *x.Method 66 | } 67 | return "" 68 | } 69 | 70 | type StatisticsReply struct { 71 | state protoimpl.MessageState 72 | sizeCache protoimpl.SizeCache 73 | unknownFields protoimpl.UnknownFields 74 | 75 | AccessCount int64 `protobuf:"varint,1,opt,name=access_count,json=accessCount,proto3" json:"access_count,omitempty"` 76 | } 77 | 78 | func (x *StatisticsReply) Reset() { 79 | *x = StatisticsReply{} 80 | if protoimpl.UnsafeEnabled { 81 | mi := &file_event_proto_statistics_proto_msgTypes[1] 82 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 83 | ms.StoreMessageInfo(mi) 84 | } 85 | } 86 | 87 | func (x *StatisticsReply) String() string { 88 | return protoimpl.X.MessageStringOf(x) 89 | } 90 | 91 | func (*StatisticsReply) ProtoMessage() {} 92 | 93 | func (x *StatisticsReply) ProtoReflect() protoreflect.Message { 94 | mi := &file_event_proto_statistics_proto_msgTypes[1] 95 | if protoimpl.UnsafeEnabled && x != nil { 96 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 97 | if ms.LoadMessageInfo() == nil { 98 | ms.StoreMessageInfo(mi) 99 | } 100 | return ms 101 | } 102 | return mi.MessageOf(x) 103 | } 104 | 105 | // Deprecated: Use StatisticsReply.ProtoReflect.Descriptor instead. 106 | func (*StatisticsReply) Descriptor() ([]byte, []int) { 107 | return file_event_proto_statistics_proto_rawDescGZIP(), []int{1} 108 | } 109 | 110 | func (x *StatisticsReply) GetAccessCount() int64 { 111 | if x != nil { 112 | return x.AccessCount 113 | } 114 | return 0 115 | } 116 | 117 | type AccessEvent struct { 118 | state protoimpl.MessageState 119 | sizeCache protoimpl.SizeCache 120 | unknownFields protoimpl.UnknownFields 121 | 122 | Status uint32 `protobuf:"varint,1,opt,name=status,proto3" json:"status,omitempty"` 123 | Method string `protobuf:"bytes,2,opt,name=method,proto3" json:"method,omitempty"` 124 | Path string `protobuf:"bytes,3,opt,name=path,proto3" json:"path,omitempty"` 125 | Ip string `protobuf:"bytes,4,opt,name=ip,proto3" json:"ip,omitempty"` 126 | Latency int64 `protobuf:"varint,5,opt,name=latency,proto3" json:"latency,omitempty"` 127 | Timestamp int64 `protobuf:"varint,6,opt,name=timestamp,proto3" json:"timestamp,omitempty"` 128 | } 129 | 130 | func (x *AccessEvent) Reset() { 131 | *x = AccessEvent{} 132 | if protoimpl.UnsafeEnabled { 133 | mi := &file_event_proto_statistics_proto_msgTypes[2] 134 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 135 | ms.StoreMessageInfo(mi) 136 | } 137 | } 138 | 139 | func (x *AccessEvent) String() string { 140 | return protoimpl.X.MessageStringOf(x) 141 | } 142 | 143 | func (*AccessEvent) ProtoMessage() {} 144 | 145 | func (x *AccessEvent) ProtoReflect() protoreflect.Message { 146 | mi := &file_event_proto_statistics_proto_msgTypes[2] 147 | if protoimpl.UnsafeEnabled && x != nil { 148 | ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) 149 | if ms.LoadMessageInfo() == nil { 150 | ms.StoreMessageInfo(mi) 151 | } 152 | return ms 153 | } 154 | return mi.MessageOf(x) 155 | } 156 | 157 | // Deprecated: Use AccessEvent.ProtoReflect.Descriptor instead. 158 | func (*AccessEvent) Descriptor() ([]byte, []int) { 159 | return file_event_proto_statistics_proto_rawDescGZIP(), []int{2} 160 | } 161 | 162 | func (x *AccessEvent) GetStatus() uint32 { 163 | if x != nil { 164 | return x.Status 165 | } 166 | return 0 167 | } 168 | 169 | func (x *AccessEvent) GetMethod() string { 170 | if x != nil { 171 | return x.Method 172 | } 173 | return "" 174 | } 175 | 176 | func (x *AccessEvent) GetPath() string { 177 | if x != nil { 178 | return x.Path 179 | } 180 | return "" 181 | } 182 | 183 | func (x *AccessEvent) GetIp() string { 184 | if x != nil { 185 | return x.Ip 186 | } 187 | return "" 188 | } 189 | 190 | func (x *AccessEvent) GetLatency() int64 { 191 | if x != nil { 192 | return x.Latency 193 | } 194 | return 0 195 | } 196 | 197 | func (x *AccessEvent) GetTimestamp() int64 { 198 | if x != nil { 199 | return x.Timestamp 200 | } 201 | return 0 202 | } 203 | 204 | var File_event_proto_statistics_proto protoreflect.FileDescriptor 205 | 206 | var file_event_proto_statistics_proto_rawDesc = []byte{ 207 | 0x0a, 0x1c, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x74, 208 | 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x3b, 209 | 0x0a, 0x11, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x52, 0x65, 0x71, 0x75, 210 | 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x18, 0x01, 0x20, 211 | 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x88, 0x01, 0x01, 212 | 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x6d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x22, 0x34, 0x0a, 0x0f, 0x53, 213 | 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x12, 0x21, 214 | 0x0a, 0x0c, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x01, 215 | 0x20, 0x01, 0x28, 0x03, 0x52, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x73, 0x73, 0x43, 0x6f, 0x75, 0x6e, 216 | 0x74, 0x22, 0x99, 0x01, 0x0a, 0x0b, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x45, 0x76, 0x65, 0x6e, 217 | 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 218 | 0x0d, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x6d, 0x65, 0x74, 219 | 0x68, 0x6f, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x6d, 0x65, 0x74, 0x68, 0x6f, 220 | 0x64, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x61, 0x74, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 221 | 0x04, 0x70, 0x61, 0x74, 0x68, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 222 | 0x09, 0x52, 0x02, 0x69, 0x70, 0x12, 0x18, 0x0a, 0x07, 0x6c, 0x61, 0x74, 0x65, 0x6e, 0x63, 0x79, 223 | 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07, 0x6c, 0x61, 0x74, 0x65, 0x6e, 0x63, 0x79, 0x12, 224 | 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, 0x06, 0x20, 0x01, 225 | 0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x32, 0x49, 0x0a, 226 | 0x11, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x53, 0x65, 0x72, 0x76, 0x69, 227 | 0x63, 0x65, 0x12, 0x34, 0x0a, 0x0a, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 228 | 0x12, 0x12, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 0x73, 0x52, 0x65, 0x71, 229 | 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x69, 0x73, 0x74, 0x69, 0x63, 230 | 0x73, 0x52, 0x65, 0x70, 0x6c, 0x79, 0x22, 0x00, 0x42, 0x0a, 0x5a, 0x08, 0x2e, 0x2e, 0x2f, 0x70, 231 | 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, 232 | } 233 | 234 | var ( 235 | file_event_proto_statistics_proto_rawDescOnce sync.Once 236 | file_event_proto_statistics_proto_rawDescData = file_event_proto_statistics_proto_rawDesc 237 | ) 238 | 239 | func file_event_proto_statistics_proto_rawDescGZIP() []byte { 240 | file_event_proto_statistics_proto_rawDescOnce.Do(func() { 241 | file_event_proto_statistics_proto_rawDescData = protoimpl.X.CompressGZIP(file_event_proto_statistics_proto_rawDescData) 242 | }) 243 | return file_event_proto_statistics_proto_rawDescData 244 | } 245 | 246 | var file_event_proto_statistics_proto_msgTypes = make([]protoimpl.MessageInfo, 3) 247 | var file_event_proto_statistics_proto_goTypes = []interface{}{ 248 | (*StatisticsRequest)(nil), // 0: StatisticsRequest 249 | (*StatisticsReply)(nil), // 1: StatisticsReply 250 | (*AccessEvent)(nil), // 2: AccessEvent 251 | } 252 | var file_event_proto_statistics_proto_depIdxs = []int32{ 253 | 0, // 0: StatisticsService.Statistics:input_type -> StatisticsRequest 254 | 1, // 1: StatisticsService.Statistics:output_type -> StatisticsReply 255 | 1, // [1:2] is the sub-list for method output_type 256 | 0, // [0:1] is the sub-list for method input_type 257 | 0, // [0:0] is the sub-list for extension type_name 258 | 0, // [0:0] is the sub-list for extension extendee 259 | 0, // [0:0] is the sub-list for field type_name 260 | } 261 | 262 | func init() { file_event_proto_statistics_proto_init() } 263 | func file_event_proto_statistics_proto_init() { 264 | if File_event_proto_statistics_proto != nil { 265 | return 266 | } 267 | if !protoimpl.UnsafeEnabled { 268 | file_event_proto_statistics_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { 269 | switch v := v.(*StatisticsRequest); i { 270 | case 0: 271 | return &v.state 272 | case 1: 273 | return &v.sizeCache 274 | case 2: 275 | return &v.unknownFields 276 | default: 277 | return nil 278 | } 279 | } 280 | file_event_proto_statistics_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { 281 | switch v := v.(*StatisticsReply); i { 282 | case 0: 283 | return &v.state 284 | case 1: 285 | return &v.sizeCache 286 | case 2: 287 | return &v.unknownFields 288 | default: 289 | return nil 290 | } 291 | } 292 | file_event_proto_statistics_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { 293 | switch v := v.(*AccessEvent); i { 294 | case 0: 295 | return &v.state 296 | case 1: 297 | return &v.sizeCache 298 | case 2: 299 | return &v.unknownFields 300 | default: 301 | return nil 302 | } 303 | } 304 | } 305 | file_event_proto_statistics_proto_msgTypes[0].OneofWrappers = []interface{}{} 306 | type x struct{} 307 | out := protoimpl.TypeBuilder{ 308 | File: protoimpl.DescBuilder{ 309 | GoPackagePath: reflect.TypeOf(x{}).PkgPath(), 310 | RawDescriptor: file_event_proto_statistics_proto_rawDesc, 311 | NumEnums: 0, 312 | NumMessages: 3, 313 | NumExtensions: 0, 314 | NumServices: 1, 315 | }, 316 | GoTypes: file_event_proto_statistics_proto_goTypes, 317 | DependencyIndexes: file_event_proto_statistics_proto_depIdxs, 318 | MessageInfos: file_event_proto_statistics_proto_msgTypes, 319 | }.Build() 320 | File_event_proto_statistics_proto = out.File 321 | file_event_proto_statistics_proto_rawDesc = nil 322 | file_event_proto_statistics_proto_goTypes = nil 323 | file_event_proto_statistics_proto_depIdxs = nil 324 | } 325 | -------------------------------------------------------------------------------- /v3/stream/proto/route_guide.pb.micro.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-micro. DO NOT EDIT. 2 | // source: stream/proto/route_guide.proto 3 | 4 | package proto 5 | 6 | import ( 7 | fmt "fmt" 8 | proto "google.golang.org/protobuf/proto" 9 | math "math" 10 | ) 11 | 12 | import ( 13 | context "context" 14 | api "github.com/asim/go-micro/v3/api" 15 | client "github.com/asim/go-micro/v3/client" 16 | server "github.com/asim/go-micro/v3/server" 17 | ) 18 | 19 | // Reference imports to suppress errors if they are not otherwise used. 20 | var _ = proto.Marshal 21 | var _ = fmt.Errorf 22 | var _ = math.Inf 23 | 24 | // Reference imports to suppress errors if they are not otherwise used. 25 | var _ api.Endpoint 26 | var _ context.Context 27 | var _ client.Option 28 | var _ server.Option 29 | 30 | // Api Endpoints for RouteGuide service 31 | 32 | func NewRouteGuideEndpoints() []*api.Endpoint { 33 | return []*api.Endpoint{} 34 | } 35 | 36 | // Client API for RouteGuide service 37 | 38 | type RouteGuideService interface { 39 | // A simple RPC. 40 | // 41 | // Obtains the feature at a given position. 42 | // 43 | // A feature with an empty name is returned if there's no feature at the given 44 | // position. 45 | GetFeature(ctx context.Context, in *Point, opts ...client.CallOption) (*Feature, error) 46 | // A server-to-client streaming RPC. 47 | // 48 | // Obtains the Features available within the given Rectangle. Results are 49 | // streamed rather than returned at once (e.g. in a response message with a 50 | // repeated field), as the rectangle may cover a large area and contain a 51 | // huge number of features. 52 | ListFeatures(ctx context.Context, in *Rectangle, opts ...client.CallOption) (RouteGuide_ListFeaturesService, error) 53 | // A client-to-server streaming RPC. 54 | // 55 | // Accepts a stream of Points on a route being traversed, returning a 56 | // RouteSummary when traversal is completed. 57 | RecordRoute(ctx context.Context, opts ...client.CallOption) (RouteGuide_RecordRouteService, error) 58 | // A Bidirectional streaming RPC. 59 | // 60 | // Accepts a stream of RouteNotes sent while a route is being traversed, 61 | // while receiving other RouteNotes (e.g. from other users). 62 | RouteChat(ctx context.Context, opts ...client.CallOption) (RouteGuide_RouteChatService, error) 63 | } 64 | 65 | type routeGuideService struct { 66 | c client.Client 67 | name string 68 | } 69 | 70 | func NewRouteGuideService(name string, c client.Client) RouteGuideService { 71 | return &routeGuideService{ 72 | c: c, 73 | name: name, 74 | } 75 | } 76 | 77 | func (c *routeGuideService) GetFeature(ctx context.Context, in *Point, opts ...client.CallOption) (*Feature, error) { 78 | req := c.c.NewRequest(c.name, "RouteGuide.GetFeature", in) 79 | out := new(Feature) 80 | err := c.c.Call(ctx, req, out, opts...) 81 | if err != nil { 82 | return nil, err 83 | } 84 | return out, nil 85 | } 86 | 87 | func (c *routeGuideService) ListFeatures(ctx context.Context, in *Rectangle, opts ...client.CallOption) (RouteGuide_ListFeaturesService, error) { 88 | req := c.c.NewRequest(c.name, "RouteGuide.ListFeatures", &Rectangle{}) 89 | stream, err := c.c.Stream(ctx, req, opts...) 90 | if err != nil { 91 | return nil, err 92 | } 93 | if err := stream.Send(in); err != nil { 94 | return nil, err 95 | } 96 | return &routeGuideServiceListFeatures{stream}, nil 97 | } 98 | 99 | type RouteGuide_ListFeaturesService interface { 100 | Context() context.Context 101 | SendMsg(interface{}) error 102 | RecvMsg(interface{}) error 103 | Close() error 104 | Recv() (*Feature, error) 105 | } 106 | 107 | type routeGuideServiceListFeatures struct { 108 | stream client.Stream 109 | } 110 | 111 | func (x *routeGuideServiceListFeatures) Close() error { 112 | return x.stream.Close() 113 | } 114 | 115 | func (x *routeGuideServiceListFeatures) Context() context.Context { 116 | return x.stream.Context() 117 | } 118 | 119 | func (x *routeGuideServiceListFeatures) SendMsg(m interface{}) error { 120 | return x.stream.Send(m) 121 | } 122 | 123 | func (x *routeGuideServiceListFeatures) RecvMsg(m interface{}) error { 124 | return x.stream.Recv(m) 125 | } 126 | 127 | func (x *routeGuideServiceListFeatures) Recv() (*Feature, error) { 128 | m := new(Feature) 129 | err := x.stream.Recv(m) 130 | if err != nil { 131 | return nil, err 132 | } 133 | return m, nil 134 | } 135 | 136 | func (c *routeGuideService) RecordRoute(ctx context.Context, opts ...client.CallOption) (RouteGuide_RecordRouteService, error) { 137 | req := c.c.NewRequest(c.name, "RouteGuide.RecordRoute", &Point{}) 138 | stream, err := c.c.Stream(ctx, req, opts...) 139 | if err != nil { 140 | return nil, err 141 | } 142 | return &routeGuideServiceRecordRoute{stream}, nil 143 | } 144 | 145 | type RouteGuide_RecordRouteService interface { 146 | Context() context.Context 147 | SendMsg(interface{}) error 148 | RecvMsg(interface{}) error 149 | Close() error 150 | Send(*Point) error 151 | } 152 | 153 | type routeGuideServiceRecordRoute struct { 154 | stream client.Stream 155 | } 156 | 157 | func (x *routeGuideServiceRecordRoute) Close() error { 158 | return x.stream.Close() 159 | } 160 | 161 | func (x *routeGuideServiceRecordRoute) Context() context.Context { 162 | return x.stream.Context() 163 | } 164 | 165 | func (x *routeGuideServiceRecordRoute) SendMsg(m interface{}) error { 166 | return x.stream.Send(m) 167 | } 168 | 169 | func (x *routeGuideServiceRecordRoute) RecvMsg(m interface{}) error { 170 | return x.stream.Recv(m) 171 | } 172 | 173 | func (x *routeGuideServiceRecordRoute) Send(m *Point) error { 174 | return x.stream.Send(m) 175 | } 176 | 177 | func (c *routeGuideService) RouteChat(ctx context.Context, opts ...client.CallOption) (RouteGuide_RouteChatService, error) { 178 | req := c.c.NewRequest(c.name, "RouteGuide.RouteChat", &RouteNote{}) 179 | stream, err := c.c.Stream(ctx, req, opts...) 180 | if err != nil { 181 | return nil, err 182 | } 183 | return &routeGuideServiceRouteChat{stream}, nil 184 | } 185 | 186 | type RouteGuide_RouteChatService interface { 187 | Context() context.Context 188 | SendMsg(interface{}) error 189 | RecvMsg(interface{}) error 190 | Close() error 191 | Send(*RouteNote) error 192 | Recv() (*RouteNote, error) 193 | } 194 | 195 | type routeGuideServiceRouteChat struct { 196 | stream client.Stream 197 | } 198 | 199 | func (x *routeGuideServiceRouteChat) Close() error { 200 | return x.stream.Close() 201 | } 202 | 203 | func (x *routeGuideServiceRouteChat) Context() context.Context { 204 | return x.stream.Context() 205 | } 206 | 207 | func (x *routeGuideServiceRouteChat) SendMsg(m interface{}) error { 208 | return x.stream.Send(m) 209 | } 210 | 211 | func (x *routeGuideServiceRouteChat) RecvMsg(m interface{}) error { 212 | return x.stream.Recv(m) 213 | } 214 | 215 | func (x *routeGuideServiceRouteChat) Send(m *RouteNote) error { 216 | return x.stream.Send(m) 217 | } 218 | 219 | func (x *routeGuideServiceRouteChat) Recv() (*RouteNote, error) { 220 | m := new(RouteNote) 221 | err := x.stream.Recv(m) 222 | if err != nil { 223 | return nil, err 224 | } 225 | return m, nil 226 | } 227 | 228 | // Server API for RouteGuide service 229 | 230 | type RouteGuideHandler interface { 231 | // A simple RPC. 232 | // 233 | // Obtains the feature at a given position. 234 | // 235 | // A feature with an empty name is returned if there's no feature at the given 236 | // position. 237 | GetFeature(context.Context, *Point, *Feature) error 238 | // A server-to-client streaming RPC. 239 | // 240 | // Obtains the Features available within the given Rectangle. Results are 241 | // streamed rather than returned at once (e.g. in a response message with a 242 | // repeated field), as the rectangle may cover a large area and contain a 243 | // huge number of features. 244 | ListFeatures(context.Context, *Rectangle, RouteGuide_ListFeaturesStream) error 245 | // A client-to-server streaming RPC. 246 | // 247 | // Accepts a stream of Points on a route being traversed, returning a 248 | // RouteSummary when traversal is completed. 249 | RecordRoute(context.Context, RouteGuide_RecordRouteStream) error 250 | // A Bidirectional streaming RPC. 251 | // 252 | // Accepts a stream of RouteNotes sent while a route is being traversed, 253 | // while receiving other RouteNotes (e.g. from other users). 254 | RouteChat(context.Context, RouteGuide_RouteChatStream) error 255 | } 256 | 257 | func RegisterRouteGuideHandler(s server.Server, hdlr RouteGuideHandler, opts ...server.HandlerOption) error { 258 | type routeGuide interface { 259 | GetFeature(ctx context.Context, in *Point, out *Feature) error 260 | ListFeatures(ctx context.Context, stream server.Stream) error 261 | RecordRoute(ctx context.Context, stream server.Stream) error 262 | RouteChat(ctx context.Context, stream server.Stream) error 263 | } 264 | type RouteGuide struct { 265 | routeGuide 266 | } 267 | h := &routeGuideHandler{hdlr} 268 | return s.Handle(s.NewHandler(&RouteGuide{h}, opts...)) 269 | } 270 | 271 | type routeGuideHandler struct { 272 | RouteGuideHandler 273 | } 274 | 275 | func (h *routeGuideHandler) GetFeature(ctx context.Context, in *Point, out *Feature) error { 276 | return h.RouteGuideHandler.GetFeature(ctx, in, out) 277 | } 278 | 279 | func (h *routeGuideHandler) ListFeatures(ctx context.Context, stream server.Stream) error { 280 | m := new(Rectangle) 281 | if err := stream.Recv(m); err != nil { 282 | return err 283 | } 284 | return h.RouteGuideHandler.ListFeatures(ctx, m, &routeGuideListFeaturesStream{stream}) 285 | } 286 | 287 | type RouteGuide_ListFeaturesStream interface { 288 | Context() context.Context 289 | SendMsg(interface{}) error 290 | RecvMsg(interface{}) error 291 | Close() error 292 | Send(*Feature) error 293 | } 294 | 295 | type routeGuideListFeaturesStream struct { 296 | stream server.Stream 297 | } 298 | 299 | func (x *routeGuideListFeaturesStream) Close() error { 300 | return x.stream.Close() 301 | } 302 | 303 | func (x *routeGuideListFeaturesStream) Context() context.Context { 304 | return x.stream.Context() 305 | } 306 | 307 | func (x *routeGuideListFeaturesStream) SendMsg(m interface{}) error { 308 | return x.stream.Send(m) 309 | } 310 | 311 | func (x *routeGuideListFeaturesStream) RecvMsg(m interface{}) error { 312 | return x.stream.Recv(m) 313 | } 314 | 315 | func (x *routeGuideListFeaturesStream) Send(m *Feature) error { 316 | return x.stream.Send(m) 317 | } 318 | 319 | func (h *routeGuideHandler) RecordRoute(ctx context.Context, stream server.Stream) error { 320 | return h.RouteGuideHandler.RecordRoute(ctx, &routeGuideRecordRouteStream{stream}) 321 | } 322 | 323 | type RouteGuide_RecordRouteStream interface { 324 | Context() context.Context 325 | SendMsg(interface{}) error 326 | RecvMsg(interface{}) error 327 | Close() error 328 | Recv() (*Point, error) 329 | } 330 | 331 | type routeGuideRecordRouteStream struct { 332 | stream server.Stream 333 | } 334 | 335 | func (x *routeGuideRecordRouteStream) Close() error { 336 | return x.stream.Close() 337 | } 338 | 339 | func (x *routeGuideRecordRouteStream) Context() context.Context { 340 | return x.stream.Context() 341 | } 342 | 343 | func (x *routeGuideRecordRouteStream) SendMsg(m interface{}) error { 344 | return x.stream.Send(m) 345 | } 346 | 347 | func (x *routeGuideRecordRouteStream) RecvMsg(m interface{}) error { 348 | return x.stream.Recv(m) 349 | } 350 | 351 | func (x *routeGuideRecordRouteStream) Recv() (*Point, error) { 352 | m := new(Point) 353 | if err := x.stream.Recv(m); err != nil { 354 | return nil, err 355 | } 356 | return m, nil 357 | } 358 | 359 | func (h *routeGuideHandler) RouteChat(ctx context.Context, stream server.Stream) error { 360 | return h.RouteGuideHandler.RouteChat(ctx, &routeGuideRouteChatStream{stream}) 361 | } 362 | 363 | type RouteGuide_RouteChatStream interface { 364 | Context() context.Context 365 | SendMsg(interface{}) error 366 | RecvMsg(interface{}) error 367 | Close() error 368 | Send(*RouteNote) error 369 | Recv() (*RouteNote, error) 370 | } 371 | 372 | type routeGuideRouteChatStream struct { 373 | stream server.Stream 374 | } 375 | 376 | func (x *routeGuideRouteChatStream) Close() error { 377 | return x.stream.Close() 378 | } 379 | 380 | func (x *routeGuideRouteChatStream) Context() context.Context { 381 | return x.stream.Context() 382 | } 383 | 384 | func (x *routeGuideRouteChatStream) SendMsg(m interface{}) error { 385 | return x.stream.Send(m) 386 | } 387 | 388 | func (x *routeGuideRouteChatStream) RecvMsg(m interface{}) error { 389 | return x.stream.Recv(m) 390 | } 391 | 392 | func (x *routeGuideRouteChatStream) Send(m *RouteNote) error { 393 | return x.stream.Send(m) 394 | } 395 | 396 | func (x *routeGuideRouteChatStream) Recv() (*RouteNote, error) { 397 | m := new(RouteNote) 398 | if err := x.stream.Recv(m); err != nil { 399 | return nil, err 400 | } 401 | return m, nil 402 | } 403 | -------------------------------------------------------------------------------- /v4/proto/route_guide.pb.micro.go: -------------------------------------------------------------------------------- 1 | // Code generated by protoc-gen-micro. DO NOT EDIT. 2 | // source: proto/route_guide.proto 3 | 4 | package proto 5 | 6 | import ( 7 | fmt "fmt" 8 | proto "google.golang.org/protobuf/proto" 9 | math "math" 10 | ) 11 | 12 | import ( 13 | context "context" 14 | api "go-micro.dev/v4/api" 15 | client "go-micro.dev/v4/client" 16 | server "go-micro.dev/v4/server" 17 | ) 18 | 19 | // Reference imports to suppress errors if they are not otherwise used. 20 | var _ = proto.Marshal 21 | var _ = fmt.Errorf 22 | var _ = math.Inf 23 | 24 | // Reference imports to suppress errors if they are not otherwise used. 25 | var _ api.Endpoint 26 | var _ context.Context 27 | var _ client.Option 28 | var _ server.Option 29 | 30 | // Api Endpoints for RouteGuide service 31 | 32 | func NewRouteGuideEndpoints() []*api.Endpoint { 33 | return []*api.Endpoint{} 34 | } 35 | 36 | // Client API for RouteGuide service 37 | 38 | type RouteGuideService interface { 39 | // A simple RPC. 40 | // 41 | // Obtains the feature at a given position. 42 | // 43 | // A feature with an empty name is returned if there's no feature at the given 44 | // position. 45 | GetFeature(ctx context.Context, in *Point, opts ...client.CallOption) (*Feature, error) 46 | // A server-to-client streaming RPC. 47 | // 48 | // Obtains the Features available within the given Rectangle. Results are 49 | // streamed rather than returned at once (e.g. in a response message with a 50 | // repeated field), as the rectangle may cover a large area and contain a 51 | // huge number of features. 52 | ListFeatures(ctx context.Context, in *Rectangle, opts ...client.CallOption) (RouteGuide_ListFeaturesService, error) 53 | // A client-to-server streaming RPC. 54 | // 55 | // Accepts a stream of Points on a route being traversed, returning a 56 | // RouteSummary when traversal is completed. 57 | RecordRoute(ctx context.Context, opts ...client.CallOption) (RouteGuide_RecordRouteService, error) 58 | // A Bidirectional streaming RPC. 59 | // 60 | // Accepts a stream of RouteNotes sent while a route is being traversed, 61 | // while receiving other RouteNotes (e.g. from other users). 62 | RouteChat(ctx context.Context, opts ...client.CallOption) (RouteGuide_RouteChatService, error) 63 | } 64 | 65 | type routeGuideService struct { 66 | c client.Client 67 | name string 68 | } 69 | 70 | func NewRouteGuideService(name string, c client.Client) RouteGuideService { 71 | return &routeGuideService{ 72 | c: c, 73 | name: name, 74 | } 75 | } 76 | 77 | func (c *routeGuideService) GetFeature(ctx context.Context, in *Point, opts ...client.CallOption) (*Feature, error) { 78 | req := c.c.NewRequest(c.name, "RouteGuide.GetFeature", in) 79 | out := new(Feature) 80 | err := c.c.Call(ctx, req, out, opts...) 81 | if err != nil { 82 | return nil, err 83 | } 84 | return out, nil 85 | } 86 | 87 | func (c *routeGuideService) ListFeatures(ctx context.Context, in *Rectangle, opts ...client.CallOption) (RouteGuide_ListFeaturesService, error) { 88 | req := c.c.NewRequest(c.name, "RouteGuide.ListFeatures", &Rectangle{}) 89 | stream, err := c.c.Stream(ctx, req, opts...) 90 | if err != nil { 91 | return nil, err 92 | } 93 | if err := stream.Send(in); err != nil { 94 | return nil, err 95 | } 96 | return &routeGuideServiceListFeatures{stream}, nil 97 | } 98 | 99 | type RouteGuide_ListFeaturesService interface { 100 | Context() context.Context 101 | SendMsg(interface{}) error 102 | RecvMsg(interface{}) error 103 | CloseSend() error 104 | Close() error 105 | Recv() (*Feature, error) 106 | } 107 | 108 | type routeGuideServiceListFeatures struct { 109 | stream client.Stream 110 | } 111 | 112 | func (x *routeGuideServiceListFeatures) CloseSend() error { 113 | return x.stream.CloseSend() 114 | } 115 | 116 | func (x *routeGuideServiceListFeatures) Close() error { 117 | return x.stream.Close() 118 | } 119 | 120 | func (x *routeGuideServiceListFeatures) Context() context.Context { 121 | return x.stream.Context() 122 | } 123 | 124 | func (x *routeGuideServiceListFeatures) SendMsg(m interface{}) error { 125 | return x.stream.Send(m) 126 | } 127 | 128 | func (x *routeGuideServiceListFeatures) RecvMsg(m interface{}) error { 129 | return x.stream.Recv(m) 130 | } 131 | 132 | func (x *routeGuideServiceListFeatures) Recv() (*Feature, error) { 133 | m := new(Feature) 134 | err := x.stream.Recv(m) 135 | if err != nil { 136 | return nil, err 137 | } 138 | return m, nil 139 | } 140 | 141 | func (c *routeGuideService) RecordRoute(ctx context.Context, opts ...client.CallOption) (RouteGuide_RecordRouteService, error) { 142 | req := c.c.NewRequest(c.name, "RouteGuide.RecordRoute", &Point{}) 143 | stream, err := c.c.Stream(ctx, req, opts...) 144 | if err != nil { 145 | return nil, err 146 | } 147 | return &routeGuideServiceRecordRoute{stream}, nil 148 | } 149 | 150 | type RouteGuide_RecordRouteService interface { 151 | Context() context.Context 152 | SendMsg(interface{}) error 153 | RecvMsg(interface{}) error 154 | CloseSend() error 155 | Close() error 156 | Send(*Point) error 157 | } 158 | 159 | type routeGuideServiceRecordRoute struct { 160 | stream client.Stream 161 | } 162 | 163 | func (x *routeGuideServiceRecordRoute) CloseSend() error { 164 | return x.stream.CloseSend() 165 | } 166 | 167 | func (x *routeGuideServiceRecordRoute) Close() error { 168 | return x.stream.Close() 169 | } 170 | 171 | func (x *routeGuideServiceRecordRoute) Context() context.Context { 172 | return x.stream.Context() 173 | } 174 | 175 | func (x *routeGuideServiceRecordRoute) SendMsg(m interface{}) error { 176 | return x.stream.Send(m) 177 | } 178 | 179 | func (x *routeGuideServiceRecordRoute) RecvMsg(m interface{}) error { 180 | return x.stream.Recv(m) 181 | } 182 | 183 | func (x *routeGuideServiceRecordRoute) Send(m *Point) error { 184 | return x.stream.Send(m) 185 | } 186 | 187 | func (c *routeGuideService) RouteChat(ctx context.Context, opts ...client.CallOption) (RouteGuide_RouteChatService, error) { 188 | req := c.c.NewRequest(c.name, "RouteGuide.RouteChat", &RouteNote{}) 189 | stream, err := c.c.Stream(ctx, req, opts...) 190 | if err != nil { 191 | return nil, err 192 | } 193 | return &routeGuideServiceRouteChat{stream}, nil 194 | } 195 | 196 | type RouteGuide_RouteChatService interface { 197 | Context() context.Context 198 | SendMsg(interface{}) error 199 | RecvMsg(interface{}) error 200 | CloseSend() error 201 | Close() error 202 | Send(*RouteNote) error 203 | Recv() (*RouteNote, error) 204 | } 205 | 206 | type routeGuideServiceRouteChat struct { 207 | stream client.Stream 208 | } 209 | 210 | func (x *routeGuideServiceRouteChat) CloseSend() error { 211 | return x.stream.CloseSend() 212 | } 213 | 214 | func (x *routeGuideServiceRouteChat) Close() error { 215 | return x.stream.Close() 216 | } 217 | 218 | func (x *routeGuideServiceRouteChat) Context() context.Context { 219 | return x.stream.Context() 220 | } 221 | 222 | func (x *routeGuideServiceRouteChat) SendMsg(m interface{}) error { 223 | return x.stream.Send(m) 224 | } 225 | 226 | func (x *routeGuideServiceRouteChat) RecvMsg(m interface{}) error { 227 | return x.stream.Recv(m) 228 | } 229 | 230 | func (x *routeGuideServiceRouteChat) Send(m *RouteNote) error { 231 | return x.stream.Send(m) 232 | } 233 | 234 | func (x *routeGuideServiceRouteChat) Recv() (*RouteNote, error) { 235 | m := new(RouteNote) 236 | err := x.stream.Recv(m) 237 | if err != nil { 238 | return nil, err 239 | } 240 | return m, nil 241 | } 242 | 243 | // Server API for RouteGuide service 244 | 245 | type RouteGuideHandler interface { 246 | // A simple RPC. 247 | // 248 | // Obtains the feature at a given position. 249 | // 250 | // A feature with an empty name is returned if there's no feature at the given 251 | // position. 252 | GetFeature(context.Context, *Point, *Feature) error 253 | // A server-to-client streaming RPC. 254 | // 255 | // Obtains the Features available within the given Rectangle. Results are 256 | // streamed rather than returned at once (e.g. in a response message with a 257 | // repeated field), as the rectangle may cover a large area and contain a 258 | // huge number of features. 259 | ListFeatures(context.Context, *Rectangle, RouteGuide_ListFeaturesStream) error 260 | // A client-to-server streaming RPC. 261 | // 262 | // Accepts a stream of Points on a route being traversed, returning a 263 | // RouteSummary when traversal is completed. 264 | RecordRoute(context.Context, RouteGuide_RecordRouteStream) error 265 | // A Bidirectional streaming RPC. 266 | // 267 | // Accepts a stream of RouteNotes sent while a route is being traversed, 268 | // while receiving other RouteNotes (e.g. from other users). 269 | RouteChat(context.Context, RouteGuide_RouteChatStream) error 270 | } 271 | 272 | func RegisterRouteGuideHandler(s server.Server, hdlr RouteGuideHandler, opts ...server.HandlerOption) error { 273 | type routeGuide interface { 274 | GetFeature(ctx context.Context, in *Point, out *Feature) error 275 | ListFeatures(ctx context.Context, stream server.Stream) error 276 | RecordRoute(ctx context.Context, stream server.Stream) error 277 | RouteChat(ctx context.Context, stream server.Stream) error 278 | } 279 | type RouteGuide struct { 280 | routeGuide 281 | } 282 | h := &routeGuideHandler{hdlr} 283 | return s.Handle(s.NewHandler(&RouteGuide{h}, opts...)) 284 | } 285 | 286 | type routeGuideHandler struct { 287 | RouteGuideHandler 288 | } 289 | 290 | func (h *routeGuideHandler) GetFeature(ctx context.Context, in *Point, out *Feature) error { 291 | return h.RouteGuideHandler.GetFeature(ctx, in, out) 292 | } 293 | 294 | func (h *routeGuideHandler) ListFeatures(ctx context.Context, stream server.Stream) error { 295 | m := new(Rectangle) 296 | if err := stream.Recv(m); err != nil { 297 | return err 298 | } 299 | return h.RouteGuideHandler.ListFeatures(ctx, m, &routeGuideListFeaturesStream{stream}) 300 | } 301 | 302 | type RouteGuide_ListFeaturesStream interface { 303 | Context() context.Context 304 | SendMsg(interface{}) error 305 | RecvMsg(interface{}) error 306 | Close() error 307 | Send(*Feature) error 308 | } 309 | 310 | type routeGuideListFeaturesStream struct { 311 | stream server.Stream 312 | } 313 | 314 | func (x *routeGuideListFeaturesStream) Close() error { 315 | return x.stream.Close() 316 | } 317 | 318 | func (x *routeGuideListFeaturesStream) Context() context.Context { 319 | return x.stream.Context() 320 | } 321 | 322 | func (x *routeGuideListFeaturesStream) SendMsg(m interface{}) error { 323 | return x.stream.Send(m) 324 | } 325 | 326 | func (x *routeGuideListFeaturesStream) RecvMsg(m interface{}) error { 327 | return x.stream.Recv(m) 328 | } 329 | 330 | func (x *routeGuideListFeaturesStream) Send(m *Feature) error { 331 | return x.stream.Send(m) 332 | } 333 | 334 | func (h *routeGuideHandler) RecordRoute(ctx context.Context, stream server.Stream) error { 335 | return h.RouteGuideHandler.RecordRoute(ctx, &routeGuideRecordRouteStream{stream}) 336 | } 337 | 338 | type RouteGuide_RecordRouteStream interface { 339 | Context() context.Context 340 | SendMsg(interface{}) error 341 | RecvMsg(interface{}) error 342 | Close() error 343 | Recv() (*Point, error) 344 | } 345 | 346 | type routeGuideRecordRouteStream struct { 347 | stream server.Stream 348 | } 349 | 350 | func (x *routeGuideRecordRouteStream) Close() error { 351 | return x.stream.Close() 352 | } 353 | 354 | func (x *routeGuideRecordRouteStream) Context() context.Context { 355 | return x.stream.Context() 356 | } 357 | 358 | func (x *routeGuideRecordRouteStream) SendMsg(m interface{}) error { 359 | return x.stream.Send(m) 360 | } 361 | 362 | func (x *routeGuideRecordRouteStream) RecvMsg(m interface{}) error { 363 | return x.stream.Recv(m) 364 | } 365 | 366 | func (x *routeGuideRecordRouteStream) Recv() (*Point, error) { 367 | m := new(Point) 368 | if err := x.stream.Recv(m); err != nil { 369 | return nil, err 370 | } 371 | return m, nil 372 | } 373 | 374 | func (h *routeGuideHandler) RouteChat(ctx context.Context, stream server.Stream) error { 375 | return h.RouteGuideHandler.RouteChat(ctx, &routeGuideRouteChatStream{stream}) 376 | } 377 | 378 | type RouteGuide_RouteChatStream interface { 379 | Context() context.Context 380 | SendMsg(interface{}) error 381 | RecvMsg(interface{}) error 382 | Close() error 383 | Send(*RouteNote) error 384 | Recv() (*RouteNote, error) 385 | } 386 | 387 | type routeGuideRouteChatStream struct { 388 | stream server.Stream 389 | } 390 | 391 | func (x *routeGuideRouteChatStream) Close() error { 392 | return x.stream.Close() 393 | } 394 | 395 | func (x *routeGuideRouteChatStream) Context() context.Context { 396 | return x.stream.Context() 397 | } 398 | 399 | func (x *routeGuideRouteChatStream) SendMsg(m interface{}) error { 400 | return x.stream.Send(m) 401 | } 402 | 403 | func (x *routeGuideRouteChatStream) RecvMsg(m interface{}) error { 404 | return x.stream.Recv(m) 405 | } 406 | 407 | func (x *routeGuideRouteChatStream) Send(m *RouteNote) error { 408 | return x.stream.Send(m) 409 | } 410 | 411 | func (x *routeGuideRouteChatStream) Recv() (*RouteNote, error) { 412 | m := new(RouteNote) 413 | if err := x.stream.Recv(m); err != nil { 414 | return nil, err 415 | } 416 | return m, nil 417 | } 418 | -------------------------------------------------------------------------------- /v4/stream/server/data.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "math" 7 | 8 | pb "github.com/xpunch/go-micro-example/v4/proto" 9 | ) 10 | 11 | var features []*pb.Feature 12 | 13 | func init() { 14 | if err := json.Unmarshal(testingData, &features); err != nil { 15 | panic(err) 16 | } 17 | } 18 | 19 | func inRange(point *pb.Point, rect *pb.Rectangle) bool { 20 | left := math.Min(float64(rect.Lo.Longitude), float64(rect.Hi.Longitude)) 21 | right := math.Max(float64(rect.Lo.Longitude), float64(rect.Hi.Longitude)) 22 | top := math.Max(float64(rect.Lo.Latitude), float64(rect.Hi.Latitude)) 23 | bottom := math.Min(float64(rect.Lo.Latitude), float64(rect.Hi.Latitude)) 24 | 25 | if float64(point.Longitude) >= left && 26 | float64(point.Longitude) <= right && 27 | float64(point.Latitude) >= bottom && 28 | float64(point.Latitude) <= top { 29 | return true 30 | } 31 | return false 32 | } 33 | 34 | func calcDistance(p1 *pb.Point, p2 *pb.Point) int32 { 35 | const CordFactor float64 = 1e7 36 | const R = float64(6371000) // earth radius in metres 37 | lat1 := toRadians(float64(p1.Latitude) / CordFactor) 38 | lat2 := toRadians(float64(p2.Latitude) / CordFactor) 39 | lng1 := toRadians(float64(p1.Longitude) / CordFactor) 40 | lng2 := toRadians(float64(p2.Longitude) / CordFactor) 41 | dlat := lat2 - lat1 42 | dlng := lng2 - lng1 43 | 44 | a := math.Sin(dlat/2)*math.Sin(dlat/2) + 45 | math.Cos(lat1)*math.Cos(lat2)* 46 | math.Sin(dlng/2)*math.Sin(dlng/2) 47 | c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a)) 48 | 49 | distance := R * c 50 | return int32(distance) 51 | } 52 | 53 | func toRadians(num float64) float64 { 54 | return num * math.Pi / float64(180) 55 | } 56 | 57 | func serialize(point *pb.Point) string { 58 | return fmt.Sprintf("%d %d", point.Latitude, point.Longitude) 59 | } 60 | 61 | var testingData = []byte(`[{ 62 | "location": { 63 | "latitude": 407838351, 64 | "longitude": -746143763 65 | }, 66 | "name": "Patriots Path, Mendham, NJ 07945, USA" 67 | }, { 68 | "location": { 69 | "latitude": 408122808, 70 | "longitude": -743999179 71 | }, 72 | "name": "101 New Jersey 10, Whippany, NJ 07981, USA" 73 | }, { 74 | "location": { 75 | "latitude": 413628156, 76 | "longitude": -749015468 77 | }, 78 | "name": "U.S. 6, Shohola, PA 18458, USA" 79 | }, { 80 | "location": { 81 | "latitude": 419999544, 82 | "longitude": -740371136 83 | }, 84 | "name": "5 Conners Road, Kingston, NY 12401, USA" 85 | }, { 86 | "location": { 87 | "latitude": 414008389, 88 | "longitude": -743951297 89 | }, 90 | "name": "Mid Hudson Psychiatric Center, New Hampton, NY 10958, USA" 91 | }, { 92 | "location": { 93 | "latitude": 419611318, 94 | "longitude": -746524769 95 | }, 96 | "name": "287 Flugertown Road, Livingston Manor, NY 12758, USA" 97 | }, { 98 | "location": { 99 | "latitude": 406109563, 100 | "longitude": -742186778 101 | }, 102 | "name": "4001 Tremley Point Road, Linden, NJ 07036, USA" 103 | }, { 104 | "location": { 105 | "latitude": 416802456, 106 | "longitude": -742370183 107 | }, 108 | "name": "352 South Mountain Road, Wallkill, NY 12589, USA" 109 | }, { 110 | "location": { 111 | "latitude": 412950425, 112 | "longitude": -741077389 113 | }, 114 | "name": "Bailey Turn Road, Harriman, NY 10926, USA" 115 | }, { 116 | "location": { 117 | "latitude": 412144655, 118 | "longitude": -743949739 119 | }, 120 | "name": "193-199 Wawayanda Road, Hewitt, NJ 07421, USA" 121 | }, { 122 | "location": { 123 | "latitude": 415736605, 124 | "longitude": -742847522 125 | }, 126 | "name": "406-496 Ward Avenue, Pine Bush, NY 12566, USA" 127 | }, { 128 | "location": { 129 | "latitude": 413843930, 130 | "longitude": -740501726 131 | }, 132 | "name": "162 Merrill Road, Highland Mills, NY 10930, USA" 133 | }, { 134 | "location": { 135 | "latitude": 410873075, 136 | "longitude": -744459023 137 | }, 138 | "name": "Clinton Road, West Milford, NJ 07480, USA" 139 | }, { 140 | "location": { 141 | "latitude": 412346009, 142 | "longitude": -744026814 143 | }, 144 | "name": "16 Old Brook Lane, Warwick, NY 10990, USA" 145 | }, { 146 | "location": { 147 | "latitude": 402948455, 148 | "longitude": -747903913 149 | }, 150 | "name": "3 Drake Lane, Pennington, NJ 08534, USA" 151 | }, { 152 | "location": { 153 | "latitude": 406337092, 154 | "longitude": -740122226 155 | }, 156 | "name": "6324 8th Avenue, Brooklyn, NY 11220, USA" 157 | }, { 158 | "location": { 159 | "latitude": 406421967, 160 | "longitude": -747727624 161 | }, 162 | "name": "1 Merck Access Road, Whitehouse Station, NJ 08889, USA" 163 | }, { 164 | "location": { 165 | "latitude": 416318082, 166 | "longitude": -749677716 167 | }, 168 | "name": "78-98 Schalck Road, Narrowsburg, NY 12764, USA" 169 | }, { 170 | "location": { 171 | "latitude": 415301720, 172 | "longitude": -748416257 173 | }, 174 | "name": "282 Lakeview Drive Road, Highland Lake, NY 12743, USA" 175 | }, { 176 | "location": { 177 | "latitude": 402647019, 178 | "longitude": -747071791 179 | }, 180 | "name": "330 Evelyn Avenue, Hamilton Township, NJ 08619, USA" 181 | }, { 182 | "location": { 183 | "latitude": 412567807, 184 | "longitude": -741058078 185 | }, 186 | "name": "New York State Reference Route 987E, Southfields, NY 10975, USA" 187 | }, { 188 | "location": { 189 | "latitude": 416855156, 190 | "longitude": -744420597 191 | }, 192 | "name": "103-271 Tempaloni Road, Ellenville, NY 12428, USA" 193 | }, { 194 | "location": { 195 | "latitude": 404663628, 196 | "longitude": -744820157 197 | }, 198 | "name": "1300 Airport Road, North Brunswick Township, NJ 08902, USA" 199 | }, { 200 | "location": { 201 | "latitude": 407113723, 202 | "longitude": -749746483 203 | }, 204 | "name": "" 205 | }, { 206 | "location": { 207 | "latitude": 402133926, 208 | "longitude": -743613249 209 | }, 210 | "name": "" 211 | }, { 212 | "location": { 213 | "latitude": 400273442, 214 | "longitude": -741220915 215 | }, 216 | "name": "" 217 | }, { 218 | "location": { 219 | "latitude": 411236786, 220 | "longitude": -744070769 221 | }, 222 | "name": "" 223 | }, { 224 | "location": { 225 | "latitude": 411633782, 226 | "longitude": -746784970 227 | }, 228 | "name": "211-225 Plains Road, Augusta, NJ 07822, USA" 229 | }, { 230 | "location": { 231 | "latitude": 415830701, 232 | "longitude": -742952812 233 | }, 234 | "name": "" 235 | }, { 236 | "location": { 237 | "latitude": 413447164, 238 | "longitude": -748712898 239 | }, 240 | "name": "165 Pedersen Ridge Road, Milford, PA 18337, USA" 241 | }, { 242 | "location": { 243 | "latitude": 405047245, 244 | "longitude": -749800722 245 | }, 246 | "name": "100-122 Locktown Road, Frenchtown, NJ 08825, USA" 247 | }, { 248 | "location": { 249 | "latitude": 418858923, 250 | "longitude": -746156790 251 | }, 252 | "name": "" 253 | }, { 254 | "location": { 255 | "latitude": 417951888, 256 | "longitude": -748484944 257 | }, 258 | "name": "650-652 Willi Hill Road, Swan Lake, NY 12783, USA" 259 | }, { 260 | "location": { 261 | "latitude": 407033786, 262 | "longitude": -743977337 263 | }, 264 | "name": "26 East 3rd Street, New Providence, NJ 07974, USA" 265 | }, { 266 | "location": { 267 | "latitude": 417548014, 268 | "longitude": -740075041 269 | }, 270 | "name": "" 271 | }, { 272 | "location": { 273 | "latitude": 410395868, 274 | "longitude": -744972325 275 | }, 276 | "name": "" 277 | }, { 278 | "location": { 279 | "latitude": 404615353, 280 | "longitude": -745129803 281 | }, 282 | "name": "" 283 | }, { 284 | "location": { 285 | "latitude": 406589790, 286 | "longitude": -743560121 287 | }, 288 | "name": "611 Lawrence Avenue, Westfield, NJ 07090, USA" 289 | }, { 290 | "location": { 291 | "latitude": 414653148, 292 | "longitude": -740477477 293 | }, 294 | "name": "18 Lannis Avenue, New Windsor, NY 12553, USA" 295 | }, { 296 | "location": { 297 | "latitude": 405957808, 298 | "longitude": -743255336 299 | }, 300 | "name": "82-104 Amherst Avenue, Colonia, NJ 07067, USA" 301 | }, { 302 | "location": { 303 | "latitude": 411733589, 304 | "longitude": -741648093 305 | }, 306 | "name": "170 Seven Lakes Drive, Sloatsburg, NY 10974, USA" 307 | }, { 308 | "location": { 309 | "latitude": 412676291, 310 | "longitude": -742606606 311 | }, 312 | "name": "1270 Lakes Road, Monroe, NY 10950, USA" 313 | }, { 314 | "location": { 315 | "latitude": 409224445, 316 | "longitude": -748286738 317 | }, 318 | "name": "509-535 Alphano Road, Great Meadows, NJ 07838, USA" 319 | }, { 320 | "location": { 321 | "latitude": 406523420, 322 | "longitude": -742135517 323 | }, 324 | "name": "652 Garden Street, Elizabeth, NJ 07202, USA" 325 | }, { 326 | "location": { 327 | "latitude": 401827388, 328 | "longitude": -740294537 329 | }, 330 | "name": "349 Sea Spray Court, Neptune City, NJ 07753, USA" 331 | }, { 332 | "location": { 333 | "latitude": 410564152, 334 | "longitude": -743685054 335 | }, 336 | "name": "13-17 Stanley Street, West Milford, NJ 07480, USA" 337 | }, { 338 | "location": { 339 | "latitude": 408472324, 340 | "longitude": -740726046 341 | }, 342 | "name": "47 Industrial Avenue, Teterboro, NJ 07608, USA" 343 | }, { 344 | "location": { 345 | "latitude": 412452168, 346 | "longitude": -740214052 347 | }, 348 | "name": "5 White Oak Lane, Stony Point, NY 10980, USA" 349 | }, { 350 | "location": { 351 | "latitude": 409146138, 352 | "longitude": -746188906 353 | }, 354 | "name": "Berkshire Valley Management Area Trail, Jefferson, NJ, USA" 355 | }, { 356 | "location": { 357 | "latitude": 404701380, 358 | "longitude": -744781745 359 | }, 360 | "name": "1007 Jersey Avenue, New Brunswick, NJ 08901, USA" 361 | }, { 362 | "location": { 363 | "latitude": 409642566, 364 | "longitude": -746017679 365 | }, 366 | "name": "6 East Emerald Isle Drive, Lake Hopatcong, NJ 07849, USA" 367 | }, { 368 | "location": { 369 | "latitude": 408031728, 370 | "longitude": -748645385 371 | }, 372 | "name": "1358-1474 New Jersey 57, Port Murray, NJ 07865, USA" 373 | }, { 374 | "location": { 375 | "latitude": 413700272, 376 | "longitude": -742135189 377 | }, 378 | "name": "367 Prospect Road, Chester, NY 10918, USA" 379 | }, { 380 | "location": { 381 | "latitude": 404310607, 382 | "longitude": -740282632 383 | }, 384 | "name": "10 Simon Lake Drive, Atlantic Highlands, NJ 07716, USA" 385 | }, { 386 | "location": { 387 | "latitude": 409319800, 388 | "longitude": -746201391 389 | }, 390 | "name": "11 Ward Street, Mount Arlington, NJ 07856, USA" 391 | }, { 392 | "location": { 393 | "latitude": 406685311, 394 | "longitude": -742108603 395 | }, 396 | "name": "300-398 Jefferson Avenue, Elizabeth, NJ 07201, USA" 397 | }, { 398 | "location": { 399 | "latitude": 419018117, 400 | "longitude": -749142781 401 | }, 402 | "name": "43 Dreher Road, Roscoe, NY 12776, USA" 403 | }, { 404 | "location": { 405 | "latitude": 412856162, 406 | "longitude": -745148837 407 | }, 408 | "name": "Swan Street, Pine Island, NY 10969, USA" 409 | }, { 410 | "location": { 411 | "latitude": 416560744, 412 | "longitude": -746721964 413 | }, 414 | "name": "66 Pleasantview Avenue, Monticello, NY 12701, USA" 415 | }, { 416 | "location": { 417 | "latitude": 405314270, 418 | "longitude": -749836354 419 | }, 420 | "name": "" 421 | }, { 422 | "location": { 423 | "latitude": 414219548, 424 | "longitude": -743327440 425 | }, 426 | "name": "" 427 | }, { 428 | "location": { 429 | "latitude": 415534177, 430 | "longitude": -742900616 431 | }, 432 | "name": "565 Winding Hills Road, Montgomery, NY 12549, USA" 433 | }, { 434 | "location": { 435 | "latitude": 406898530, 436 | "longitude": -749127080 437 | }, 438 | "name": "231 Rocky Run Road, Glen Gardner, NJ 08826, USA" 439 | }, { 440 | "location": { 441 | "latitude": 407586880, 442 | "longitude": -741670168 443 | }, 444 | "name": "100 Mount Pleasant Avenue, Newark, NJ 07104, USA" 445 | }, { 446 | "location": { 447 | "latitude": 400106455, 448 | "longitude": -742870190 449 | }, 450 | "name": "517-521 Huntington Drive, Manchester Township, NJ 08759, USA" 451 | }, { 452 | "location": { 453 | "latitude": 400066188, 454 | "longitude": -746793294 455 | }, 456 | "name": "" 457 | }, { 458 | "location": { 459 | "latitude": 418803880, 460 | "longitude": -744102673 461 | }, 462 | "name": "40 Mountain Road, Napanoch, NY 12458, USA" 463 | }, { 464 | "location": { 465 | "latitude": 414204288, 466 | "longitude": -747895140 467 | }, 468 | "name": "" 469 | }, { 470 | "location": { 471 | "latitude": 414777405, 472 | "longitude": -740615601 473 | }, 474 | "name": "" 475 | }, { 476 | "location": { 477 | "latitude": 415464475, 478 | "longitude": -747175374 479 | }, 480 | "name": "48 North Road, Forestburgh, NY 12777, USA" 481 | }, { 482 | "location": { 483 | "latitude": 404062378, 484 | "longitude": -746376177 485 | }, 486 | "name": "" 487 | }, { 488 | "location": { 489 | "latitude": 405688272, 490 | "longitude": -749285130 491 | }, 492 | "name": "" 493 | }, { 494 | "location": { 495 | "latitude": 400342070, 496 | "longitude": -748788996 497 | }, 498 | "name": "" 499 | }, { 500 | "location": { 501 | "latitude": 401809022, 502 | "longitude": -744157964 503 | }, 504 | "name": "" 505 | }, { 506 | "location": { 507 | "latitude": 404226644, 508 | "longitude": -740517141 509 | }, 510 | "name": "9 Thompson Avenue, Leonardo, NJ 07737, USA" 511 | }, { 512 | "location": { 513 | "latitude": 410322033, 514 | "longitude": -747871659 515 | }, 516 | "name": "" 517 | }, { 518 | "location": { 519 | "latitude": 407100674, 520 | "longitude": -747742727 521 | }, 522 | "name": "" 523 | }, { 524 | "location": { 525 | "latitude": 418811433, 526 | "longitude": -741718005 527 | }, 528 | "name": "213 Bush Road, Stone Ridge, NY 12484, USA" 529 | }, { 530 | "location": { 531 | "latitude": 415034302, 532 | "longitude": -743850945 533 | }, 534 | "name": "" 535 | }, { 536 | "location": { 537 | "latitude": 411349992, 538 | "longitude": -743694161 539 | }, 540 | "name": "" 541 | }, { 542 | "location": { 543 | "latitude": 404839914, 544 | "longitude": -744759616 545 | }, 546 | "name": "1-17 Bergen Court, New Brunswick, NJ 08901, USA" 547 | }, { 548 | "location": { 549 | "latitude": 414638017, 550 | "longitude": -745957854 551 | }, 552 | "name": "35 Oakland Valley Road, Cuddebackville, NY 12729, USA" 553 | }, { 554 | "location": { 555 | "latitude": 412127800, 556 | "longitude": -740173578 557 | }, 558 | "name": "" 559 | }, { 560 | "location": { 561 | "latitude": 401263460, 562 | "longitude": -747964303 563 | }, 564 | "name": "" 565 | }, { 566 | "location": { 567 | "latitude": 412843391, 568 | "longitude": -749086026 569 | }, 570 | "name": "" 571 | }, { 572 | "location": { 573 | "latitude": 418512773, 574 | "longitude": -743067823 575 | }, 576 | "name": "" 577 | }, { 578 | "location": { 579 | "latitude": 404318328, 580 | "longitude": -740835638 581 | }, 582 | "name": "42-102 Main Street, Belford, NJ 07718, USA" 583 | }, { 584 | "location": { 585 | "latitude": 419020746, 586 | "longitude": -741172328 587 | }, 588 | "name": "" 589 | }, { 590 | "location": { 591 | "latitude": 404080723, 592 | "longitude": -746119569 593 | }, 594 | "name": "" 595 | }, { 596 | "location": { 597 | "latitude": 401012643, 598 | "longitude": -744035134 599 | }, 600 | "name": "" 601 | }, { 602 | "location": { 603 | "latitude": 404306372, 604 | "longitude": -741079661 605 | }, 606 | "name": "" 607 | }, { 608 | "location": { 609 | "latitude": 403966326, 610 | "longitude": -748519297 611 | }, 612 | "name": "" 613 | }, { 614 | "location": { 615 | "latitude": 405002031, 616 | "longitude": -748407866 617 | }, 618 | "name": "" 619 | }, { 620 | "location": { 621 | "latitude": 409532885, 622 | "longitude": -742200683 623 | }, 624 | "name": "" 625 | }, { 626 | "location": { 627 | "latitude": 416851321, 628 | "longitude": -742674555 629 | }, 630 | "name": "" 631 | }, { 632 | "location": { 633 | "latitude": 406411633, 634 | "longitude": -741722051 635 | }, 636 | "name": "3387 Richmond Terrace, Staten Island, NY 10303, USA" 637 | }, { 638 | "location": { 639 | "latitude": 413069058, 640 | "longitude": -744597778 641 | }, 642 | "name": "261 Van Sickle Road, Goshen, NY 10924, USA" 643 | }, { 644 | "location": { 645 | "latitude": 418465462, 646 | "longitude": -746859398 647 | }, 648 | "name": "" 649 | }, { 650 | "location": { 651 | "latitude": 411733222, 652 | "longitude": -744228360 653 | }, 654 | "name": "" 655 | }, { 656 | "location": { 657 | "latitude": 410248224, 658 | "longitude": -747127767 659 | }, 660 | "name": "3 Hasta Way, Newton, NJ 07860, USA" 661 | }]`) 662 | --------------------------------------------------------------------------------