Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 66 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async-trait = "0.1"
[build-dependencies]
gh-workflow = "0.5.1"
tonic-build = "0.11.0"
protoc-bin-vendored = "3.0.0"

[dev-dependencies]
gh-workflow = "0.5.1"
12 changes: 6 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::path::PathBuf;

fn main() {
let mut news = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
news.push("news.proto");
tonic_build::compile_protos(news).expect("Failed to compile protos");

std::env::set_var("PROTOC", protoc_bin_vendored::protoc_bin_path().unwrap());
let out_dir = PathBuf::from(std::env::var("OUT_DIR").unwrap());

tonic_build::configure()
.file_descriptor_set_path(out_dir.join("news_descriptor.bin"))
.compile(&["news.proto"], &["proto"])
.file_descriptor_set_path(out_dir.join("grpc_descriptor.bin"))
.compile(
&["proto/news.proto", "proto/posts.proto", "proto/users.proto"],
&["proto"],
)
.unwrap();
}
File renamed without changes.
39 changes: 39 additions & 0 deletions proto/posts.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
syntax = "proto3";

package posts;

message Post {
int32 user_id = 1;
int32 id = 2;
string title = 3;
string body = 4;
}

message Filter {
optional int32 user_id = 1;
}

message PostList {
repeated Post posts = 1;
}

message PostRequest {
int32 id = 1;
}

message PostResponse {
Post post = 1;
}

message DeleteResponse {
bool success = 1;
string message = 2;
}

service PostService {
rpc ListPosts(Filter) returns (PostList);
rpc GetPost(PostRequest) returns (Post);
rpc CreatePost(Post) returns (PostResponse);
rpc UpdatePost(Post) returns (PostResponse);
rpc DeletePost(PostRequest) returns (DeleteResponse);
}
69 changes: 69 additions & 0 deletions proto/users.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
syntax = "proto3";

package users;

message Geo {
string lat = 1;
string lng = 2;
}

message Address {
string street = 1;
string suite = 2;
string city = 3;
string zipcode = 4;
Geo geo = 5;
}

message Company {
string name = 1;
string catch_phrase = 2;
string bs = 3;
}

message User {
int32 id = 1;
string name = 2;
string username = 3;
string email = 4;
Address address = 5;
string phone = 6;
string website = 7;
Company company = 8;
}

message Filter {
repeated int32 id = 1;
}

message UserList {
repeated User users = 1;
}

message UserRequest {
int32 id = 1;
}

message UserResponse {
User user = 1;
}

message PatchUserRequest {
int32 id = 1;
optional string name = 2;
optional string username = 3;
optional string email = 4;
}

message DeleteResponse {
bool success = 1;
string message = 2;
}

service UserService {
rpc ListUsers(Filter) returns (UserList);
rpc GetUser(UserRequest) returns (User);
rpc CreateUser(User) returns (UserResponse);
rpc PatchUser(PatchUserRequest) returns (UserResponse);
rpc DeleteUser(UserRequest) returns (DeleteResponse);
}
Loading