-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2eac036
commit aec36d2
Showing
14 changed files
with
244 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
# go | ||
|
||
We use Gazelle to generate the `BUILD.bazel` files for this project. Simply do: | ||
We use Gazelle to generate the `BUILD.bazel` files for this project. You'll notice for the `gazelle/` example, there are no `BUILD.bazel` files in there so simply do the following to create them: | ||
```bash | ||
bazel run //:gazelle | ||
``` | ||
# generates the BUILD files | ||
bazel run gazelle | ||
# executes the binary | ||
bazel run //go/gazelle | ||
|
||
## grpc | ||
|
||
For the `grpc` examples, you'll need two terminals open. One to run the server: | ||
```bash | ||
bazel run //go/grpc/server | ||
``` | ||
|
||
Another to act as the client: | ||
```bash | ||
bazel run //go/grpc/client -- --echo="hello" | ||
``` |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
load("@rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
go_library( | ||
name = "client_lib", | ||
srcs = ["main.go"], | ||
importpath = "github.com/Qarik-Group/disruptor/projects/bzl7/go/grpc/client", | ||
visibility = ["//visibility:private"], | ||
deps = [ | ||
"//go/grpc/proto:grpc", | ||
"@org_golang_google_grpc//:go_default_library", | ||
"@org_golang_google_grpc//credentials/insecure", | ||
], | ||
) | ||
|
||
go_binary( | ||
name = "client", | ||
embed = [":client_lib"], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Package main implements a client for the Echoer service. | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"log" | ||
"time" | ||
|
||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
|
||
pb "github.com/Qarik-Group/disruptor/projects/bzl7/go/grpc/proto" | ||
) | ||
|
||
var ( | ||
address = flag.String("address", "localhost:50051", "connection address") | ||
echo = flag.String("echo", "", "Echo") | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
connection, err := grpc.Dial( | ||
*address, | ||
grpc.WithTransportCredentials( | ||
insecure.NewCredentials(), | ||
), | ||
) | ||
if err != nil { | ||
log.Fatalln("error: ", err) | ||
} | ||
defer connection.Close() | ||
|
||
echoClient := pb.NewEchoerClient(connection) | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
|
||
response, err := echoClient.SendEcho(ctx, &pb.EchoRequest{Request: *echo}) | ||
if err != nil { | ||
log.Fatalln("error: ", err) | ||
} | ||
log.Println("Response: ", response.GetMessage()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module github.com/Qarik-Group/disruptor/projects/bzl7/go/grpc | ||
|
||
go 1.22.2 | ||
|
||
require google.golang.org/grpc v1.63.2 | ||
|
||
require ( | ||
golang.org/x/net v0.21.0 // indirect | ||
golang.org/x/sys v0.17.0 // indirect | ||
golang.org/x/text v0.14.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect | ||
google.golang.org/protobuf v1.33.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= | ||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= | ||
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= | ||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= | ||
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= | ||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= | ||
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de h1:F6qOa9AZTYJXOUEr4jDysRDLrm4PHePlge4v4TGAlxY= | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de h1:cZGRis4/ot9uVm639a+rHCUaG0JJHEsdyzSQTMX+suY= | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de/go.mod h1:H4O17MA/PE9BsGx3w+a+W2VOLLD1Qf7oJneAoU6WktY= | ||
google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= | ||
google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= | ||
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= | ||
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
load("@rules_go//go:def.bzl", "go_library") | ||
load("@rules_go//proto:def.bzl", "go_proto_library") | ||
load("@rules_proto//proto:defs.bzl", "proto_library") | ||
|
||
proto_library( | ||
name = "grpc_proto", | ||
srcs = ["echo.proto"], | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_proto_library( | ||
name = "grpc_go_proto", | ||
compilers = ["@rules_go//proto:go_grpc"], | ||
importpath = "github.com/Qarik-Group/disruptor/projects/bzl7/go/grpc/proto", | ||
proto = ":grpc_proto", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
go_library( | ||
name = "grpc", | ||
embed = [":grpc_go_proto"], | ||
importpath = "github.com/Qarik-Group/disruptor/projects/bzl7/go/grpc/proto", | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
syntax = "proto3"; | ||
|
||
option go_package = "github.com/Qarik-Group/disruptor/projects/bzl7/go/grpc"; | ||
|
||
package echo; | ||
|
||
// The echo service definition. | ||
service Echoer { | ||
// Sends an echo request. | ||
rpc SendEcho (EchoRequest) returns (EchoReply) {} | ||
} | ||
|
||
// The request echo. | ||
message EchoRequest { | ||
string request = 1; | ||
} | ||
|
||
// The response message containing the echo | ||
message EchoReply { | ||
string message = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
load("@rules_go//go:def.bzl", "go_binary", "go_library") | ||
|
||
go_library( | ||
name = "server_lib", | ||
srcs = ["main.go"], | ||
importpath = "github.com/Qarik-Group/disruptor/projects/bzl7/go/grpc/server", | ||
visibility = ["//visibility:private"], | ||
deps = [ | ||
"//go/grpc/proto:grpc", | ||
"@org_golang_google_grpc//:go_default_library", | ||
], | ||
) | ||
|
||
go_binary( | ||
name = "server", | ||
embed = [":server_lib"], | ||
visibility = ["//visibility:public"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Package main implements a server for the Echoer service. | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net" | ||
|
||
pb "github.com/Qarik-Group/disruptor/projects/bzl7/go/grpc/proto" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
var ( | ||
port = flag.Int("port", 50051, "The server port") | ||
) | ||
|
||
type server struct { | ||
pb.UnimplementedEchoerServer | ||
} | ||
|
||
// SendEcho implements echo.EchoerServer | ||
func (s *server) SendEcho(ctx context.Context, in *pb.EchoRequest) (*pb.EchoReply, error) { | ||
request := in.GetRequest() | ||
log.Printf("Received: %v", request) | ||
return &pb.EchoReply{Message: request}, nil | ||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) | ||
if err != nil { | ||
log.Fatalf("failed to listen: %v", err) | ||
} | ||
|
||
grpcServer := grpc.NewServer() | ||
pb.RegisterEchoerServer(grpcServer, &server{}) | ||
log.Printf("server listening at %v", listener.Addr()) | ||
|
||
if err := grpcServer.Serve(listener); err != nil { | ||
log.Fatalf("failed to serve: %v", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters