Skip to content

Commit

Permalink
Add new test server for reflectoin
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Reiter committed Sep 28, 2024
1 parent 848fb95 commit 49efefb
Show file tree
Hide file tree
Showing 21 changed files with 222 additions and 27 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/target
/example/grpc_simple/proto
/example/grpc_simple/grpc-simple
/example/server/simple/proto
/example/server/simple/simple
/example/server/reflection/proto
/example/server/reflection/simple
/wireman/debug.log
/wireman/cfg.json
/wireman/history
Expand Down
26 changes: 26 additions & 0 deletions example/server/reflection/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
GOCMD=go
GOBUILD=$(GOCMD) build
GOCLEAN=$(GOCMD) clean
PROTOC=protoc
PROTOS=

PROTOC_GEN_GO=--go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative

BINARY_NAME=reflection

out = "."

all: clean build run

build:
$(PROTOC) $(PROTOC_GEN_GO) order.proto
$(GOBUILD) -o $(BINARY_NAME) -v ./main.go

clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
rm -f proto/order.pb.go
rm -f proto/order_grpc.pb.go

run: build
./$(BINARY_NAME)
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 38 additions & 0 deletions example/server/reflection/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"flag"
"fmt"
"log"
"net"

pb "grpc_simple/proto"

"google.golang.org/grpc"
"google.golang.org/grpc/reflection"
)

var (
port = flag.Int("port", 50052, "The server port")
)

type Server struct {
pb.UnimplementedOrderServiceServer
}

func main() {
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil {
log.Fatalf("failed to listen: %v", err)
}

s := grpc.NewServer()
pb.RegisterOrderServiceServer(s, &Server{})

reflection.Register(s)

fmt.Println("Listening on", lis.Addr())
if err := s.Serve(lis); err != nil {
log.Fatalf("Failed to serve grpc Server: %v", err)
}
}
41 changes: 41 additions & 0 deletions example/server/reflection/order.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
syntax = "proto3";

option go_package = "./proto";

package proto;

service OrderService {
// Get a order by its id
rpc GetOrder (GetOrderReq) returns (GetOrderResp) {}
// Return all available orders
rpc ListOrders (ListOrdersReq) returns (ListOrdersResp) {}
}

message GetOrderReq {
// The account id.
string account_id = 1;
// The id of the order.
string order_id = 2;
}

message GetOrderResp {
// The order matching the order_id.
Order order = 1;
}

message ListOrdersReq {
// The account id.
string account_id = 1;
}

message ListOrdersResp {
// All available orders.
repeated Order orders = 1;
}

message Order {
// The id of the order.
string id = 1;
// The name of the order.
string name = 2;
}
Binary file added example/server/reflection/reflection
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ PROTOS=

PROTOC_GEN_GO=--go_out=./proto --go_opt=paths=source_relative --go-grpc_out=./proto --go-grpc_opt=paths=source_relative

BINARY_NAME=grpc-simple
BINARY_NAME=simple

out = "."

Expand Down
16 changes: 16 additions & 0 deletions example/server/simple/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Running the server

```
make run
```

## Calling the endpoints
```
grpcurl -proto greeter.proto -plaintext -d '{"name":"Alice"}' localhost:50051 proto.Greeter/SayHello
grpcurl -proto timekeeper.proto -plaintext localhost:50051 proto.TimeKeeper/GetDate
grpcurl -proto timekeeper.proto -plaintext -d '{"number":1}' localhost:50051 proto.TimeKeeper/GetNameOfMonth
grpcurl -proto debugger.proto -plaintext -H 'your-metadata-key: your-metadata-value' localhost:50051 proto.Debugger/GetMetadata
```
File renamed without changes.
17 changes: 17 additions & 0 deletions example/server/simple/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module grpc_simple

go 1.21

toolchain go1.22.7

require google.golang.org/grpc v1.67.0

require google.golang.org/protobuf v1.34.2

require golang.org/x/net v0.29.0 // indirect

require (
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240924160255-9d4c2d233b61 // indirect
)
34 changes: 34 additions & 0 deletions example/server/simple/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.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=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17 h1:Jyp0Hsi0bmHXG6k9eATXoYtjd6e2UzZ1SCn/wIupY14=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231106174013-bbf56f31fb17/go.mod h1:oQ5rr10WTTMvP4A36n8JpR1OrO1BEiV4f78CneXZxkA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240924160255-9d4c2d233b61 h1:N9BgCIAUvn/M+p4NJccWPWb3BWh88+zyL0ll9HgbEeM=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240924160255-9d4c2d233b61/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.61.0 h1:TOvOcuXn30kRao+gfcvsebNEa5iZIiLkisYEkf7R7o0=
google.golang.org/grpc v1.61.0/go.mod h1:VUbo7IFqmF1QtCAstipjG0GIoq49KvMe9+h1jFLBNJs=
google.golang.org/grpc v1.67.0 h1:IdH9y6PF5MPSdAntIcpjQ+tXO41pcQsfZV2RxtQgVcw=
google.golang.org/grpc v1.67.0/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
File renamed without changes.
3 changes: 0 additions & 3 deletions example/grpc_simple/main.go → example/server/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/reflection"
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
)

Expand Down Expand Up @@ -146,8 +145,6 @@ func main() {
pb.RegisterDebuggerServer(s, &Server{})
pb.RegisterTestServiceServer(s, &Server{})

reflection.Register(s)

fmt.Println("Listening on", lis.Addr())
if err := s.Serve(lis); err != nil {
log.Fatalf("Failed to serve grpc Server: %v", err)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
25 changes: 24 additions & 1 deletion wireman/src/events/selection/methods.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::context::{AppContext, SelectionTab};
use crate::{
context::{AppContext, SelectionTab},
model::selection::SelectionMode,
};
use event_handler::{EventHandler, KeyCode, KeyEvent};
use std::fmt;

Expand All @@ -13,6 +16,8 @@ pub enum MethodsSelectionEvents {
Unselect,
ClearSearch,
GoToServices,
ReflectionMode,
FileMode,
}

impl fmt::Display for MethodsSelectionEvents {
Expand All @@ -27,6 +32,8 @@ impl fmt::Display for MethodsSelectionEvents {
MethodsSelectionEvents::Unselect => "Unselect",
MethodsSelectionEvents::ClearSearch => "Clear Search",
MethodsSelectionEvents::GoToServices => "Go to Services",
MethodsSelectionEvents::ReflectionMode => "Switch to Reflection Mode",
MethodsSelectionEvents::FileMode => "Switch to File Mode",
};
write!(f, "{display_str}")
}
Expand Down Expand Up @@ -86,6 +93,9 @@ impl EventHandler for MethodsSelectionEventsHandler {
MethodsSelectionEvents::GoToServices => {
ctx.selection_tab = SelectionTab::Services;
}
MethodsSelectionEvents::ReflectionMode | MethodsSelectionEvents::FileMode => {
ctx.selection.borrow_mut().toggle_reflection_mode();
}
}
}

Expand All @@ -111,6 +121,19 @@ impl EventHandler for MethodsSelectionEventsHandler {
MethodsSelectionEvents::Select,
)]);
}

if ctx.selection.borrow().selection_mode == SelectionMode::File {
map.extend([(
KeyEvent::ctrl(KeyCode::Char('r')),
MethodsSelectionEvents::ReflectionMode,
)]);
} else {
map.extend([(
KeyEvent::ctrl(KeyCode::Char('r')),
MethodsSelectionEvents::FileMode,
)]);
}

if filter_active {
map.extend([(
KeyEvent::new(KeyCode::Esc),
Expand Down
36 changes: 20 additions & 16 deletions wireman/src/events/selection/reflection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,25 @@ impl EventHandler for ReflectionDialogEventHandler {
let enable_switch_auth_tab =
selected_tab == HeadersTab::Auth && selected_editor.map_or(true, TextEditor::is_empty);
let mut map = Vec::new();
map.extend([
(
KeyEvent::new(KeyCode::Esc),
ReflectionDialogEvents::Reflection(ReflectionEvents::CloseDialog),
),
(
KeyEvent::new(KeyCode::Enter),
ReflectionDialogEvents::Reflection(ReflectionEvents::ReflectServer),
),
(
KeyEvent::ctrl(KeyCode::Char('r')),
ReflectionDialogEvents::Selection(ServicesSelectionEvents::FileMode),
),
]);
if selected_tab == HeadersTab::Addr || selected_tab == HeadersTab::None {
if !disabled_root_events {
map.extend([
(
KeyEvent::new(KeyCode::Esc),
ReflectionDialogEvents::Reflection(ReflectionEvents::CloseDialog),
),
(
KeyEvent::new(KeyCode::Enter),
ReflectionDialogEvents::Reflection(ReflectionEvents::ReflectServer),
),
(
KeyEvent::ctrl(KeyCode::Char('r')),
ReflectionDialogEvents::Selection(ServicesSelectionEvents::FileMode),
),
]);
}
if !disabled_root_events && selected_tab == HeadersTab::Addr
|| selected_tab == HeadersTab::None
{
map.extend([
(
KeyEvent::new(KeyCode::Down),
Expand All @@ -105,7 +109,7 @@ impl EventHandler for ReflectionDialogEventHandler {
),
]);
}
if selected_tab == HeadersTab::Auth {
if !disabled_root_events && selected_tab == HeadersTab::Auth {
map.extend([
(
KeyEvent::new(KeyCode::Up),
Expand Down
5 changes: 1 addition & 4 deletions wireman/src/events/selection/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ impl EventHandler for ServicesSelectionEventsHandler {
ServicesSelectionEvents::GoToMethods => {
ctx.selection_tab = SelectionTab::Methods;
}
ServicesSelectionEvents::ReflectionMode => {
ctx.selection.borrow_mut().toggle_reflection_mode();
}
ServicesSelectionEvents::FileMode => {
ServicesSelectionEvents::ReflectionMode | ServicesSelectionEvents::FileMode => {
ctx.selection.borrow_mut().toggle_reflection_mode();
}
}
Expand Down

0 comments on commit 49efefb

Please sign in to comment.