Skip to content

Commit 1e4be22

Browse files
committed
add a second rpc to Haberdasher for codegen tests
1 parent 8763029 commit 1e4be22

File tree

4 files changed

+43
-3
lines changed

4 files changed

+43
-3
lines changed

example/proto/haberdash/v1/haberdash_api.proto

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ option go_package = "haberdash.v1";
99
service HaberdasherAPI {
1010
// MakeHat produces a hat of mysterious, randomly-selected color!
1111
rpc MakeHat(MakeHatRequest) returns (MakeHatResponse);
12+
rpc GetStatus(GetStatusRequest) returns (GetStatusResponse);
1213
}
1314

1415
// Size is passed when requesting a new hat to be made. It's always
@@ -32,3 +33,9 @@ message MakeHatResponse {
3233
// Demonstrate importing an external message.
3334
google.protobuf.Timestamp timestamp = 4;
3435
}
36+
37+
message GetStatusRequest {}
38+
39+
message GetStatusResponse {
40+
string status = 1;
41+
}

example/src/bin/advanced-server.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ pub mod service {
1717
}
1818
}
1919
}
20-
use service::haberdash::v1::{self as haberdash, MakeHatRequest, MakeHatResponse};
20+
use service::haberdash::v1::{
21+
self as haberdash, GetStatusRequest, GetStatusResponse, MakeHatRequest, MakeHatResponse,
22+
};
2123

2224
async fn ping() -> &'static str {
2325
"Pong\n"
@@ -95,6 +97,16 @@ impl haberdash::HaberdasherApi for HaberdasherApiServer {
9597
}),
9698
})
9799
}
100+
101+
async fn get_status(
102+
&self,
103+
_ctx: Context,
104+
_req: GetStatusRequest,
105+
) -> Result<GetStatusResponse, HatError> {
106+
Ok(GetStatusResponse {
107+
status: "making hats".to_string(),
108+
})
109+
}
98110
}
99111

100112
// Demonstrate sending back custom extensions from the handlers.

example/src/bin/client.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ pub mod service {
1212
}
1313
}
1414

15-
use service::haberdash::v1::{HaberdasherApiClient, MakeHatRequest, MakeHatResponse};
15+
use service::haberdash::v1::{
16+
GetStatusRequest, GetStatusResponse, HaberdasherApiClient, MakeHatRequest, MakeHatResponse,
17+
};
1618

1719
#[tokio::main]
1820
pub async fn main() -> Result<(), GenericError> {
@@ -79,4 +81,11 @@ impl HaberdasherApiClient for MockHaberdasherApiClient {
7981
) -> Result<MakeHatResponse, twirp::client::ClientError> {
8082
todo!()
8183
}
84+
85+
async fn get_status(
86+
&self,
87+
_req: GetStatusRequest,
88+
) -> Result<GetStatusResponse, twirp::client::ClientError> {
89+
todo!()
90+
}
8291
}

example/src/bin/simple-server.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ pub mod service {
1212
}
1313
}
1414
}
15-
use service::haberdash::v1::{self as haberdash, MakeHatRequest, MakeHatResponse};
15+
use service::haberdash::v1::{
16+
self as haberdash, GetStatusRequest, GetStatusResponse, MakeHatRequest, MakeHatResponse,
17+
};
1618

1719
async fn ping() -> &'static str {
1820
"Pong\n"
@@ -69,6 +71,16 @@ impl haberdash::HaberdasherApi for HaberdasherApiServer {
6971
}),
7072
})
7173
}
74+
75+
async fn get_status(
76+
&self,
77+
_ctx: Context,
78+
_req: GetStatusRequest,
79+
) -> Result<GetStatusResponse, TwirpErrorResponse> {
80+
Ok(GetStatusResponse {
81+
status: "making hats".to_string(),
82+
})
83+
}
7284
}
7385

7486
// Demonstrate sending back custom extensions from the handlers.

0 commit comments

Comments
 (0)