-
Notifications
You must be signed in to change notification settings - Fork 0
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
ef65589
commit 8662c10
Showing
9 changed files
with
105 additions
and
82 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
DB_URL=localhost:5432 | ||
PRODUCTION=true |
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,11 +1,10 @@ | ||
[package] | ||
name = "server" | ||
name = "{{crate_name}}" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
tonic = "0.10.2" | ||
tokio = { version = "1.35.0", features = [] } | ||
{% for service in service_names.split(",") %} | ||
{{service.trim()}}_service = { path = "../services/{{service.trim()}}" } | ||
{% endfor %} | ||
tokio = {{"{"}} version = "1.35.0", features = [] {{"}"}} | ||
|
||
{{service_name}}_service = {{"{"}} path = "../services/{{service_name}}" {{"}"}} |
This file was deleted.
Oops, something went wrong.
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,81 @@ | ||
# GRPC Server Generator | ||
|
||
[](https://github.com/codeitlikemiley/server_template/actions/workflows/build.yml) | ||
|
||
## Requirements | ||
|
||
Note: Install the following before you can use the template generator. | ||
|
||
- [rust, rustup, cargo](https://www.rust-lang.org/tools/install) | ||
- [cargo-workspace](https://crates.io/crates/cargo-workspaces) | ||
- [cargo-generate](https://cargo-generate.github.io/cargo-generate/installation.html) | ||
- [protoc](https://grpc.io/docs/protoc-installation/) | ||
|
||
|
||
## Project Structure | ||
|
||
```sh | ||
workspace (root) | ||
├── Cargo.toml | ||
│ | ||
├── server <-- Generate Template this from **server_template** | ||
│ └── .env.example | ||
│ └── rust-toolchain.toml | ||
│ └── Cargo.toml | ||
│ └── README.md | ||
│ | ||
├── frontend | ||
│ | ||
└── services | ||
``` | ||
|
||
## Usage | ||
|
||
### Create a workspace | ||
|
||
```sh | ||
cd <workspace_root> | ||
cargo workspaces init . | ||
``` | ||
or you can simply create a `Cargo.toml` with this content | ||
|
||
```toml | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
server, # <- add this | ||
# add here services here after you generated it | ||
] | ||
``` | ||
|
||
### Generate a new GRPC server template. | ||
|
||
```sh | ||
cargo generate --git codeitlikemiley/server_template --name server | ||
cd server | ||
``` | ||
|
||
### Build , Testing and Documentation | ||
|
||
```sh | ||
cargo build | ||
cargo test | ||
cargo doc --open | ||
``` | ||
|
||
### Run Server | ||
|
||
```sh | ||
cargo run -p server | ||
``` | ||
|
||
### Adding services | ||
|
||
To add more services please check this [Services Template Repository](https://github.com/codeitlikemiley/services_template) | ||
|
||
|
||
## [License](LICENSE) | ||
|
||
## Pull Requests | ||
|
||
If you need to make changes to the template, please submit a pull request. |
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 |
---|---|---|
@@ -1,8 +1,5 @@ | ||
[placeholders] | ||
"service_names" = { type = "string", prompt = "Enter comma-separated service names (e.g., auth, user):" } | ||
|
||
[hooks] | ||
pre = ["generate_services.rhai"] | ||
"service_name" = { type = "string", prompt = "Initial Service: ", default = "example"} | ||
|
||
[template] | ||
include = ["src/**/*", "Cargo.toml"] | ||
exclude = [".liquidrc","cargo-generate.toml", ".git", ".gitignore"] |
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
[toolchain] | ||
channel = "1.74.0" | ||
components = [ "rustfmt", "clippy" ] |
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,4 +1,15 @@ | ||
use {{service_name}}_service::{{service_name}}::{{service_name}}_service_server::AuthServiceServer; | ||
use {{service_name}}_service::{{service_name}}_impl::AuthServiceImpl; | ||
use tonic::transport::Server; | ||
|
||
fn main () { | ||
println!("Hello, world!"); | ||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let addr = "[::1]:50051".parse()?; | ||
let {{service_name}}_service = AuthServiceImpl::default(); | ||
|
||
Server::builder() | ||
.add_service(AuthServiceServer::new({{service_name}}_service)) | ||
.serve(addr) | ||
.await?; | ||
Ok(()) | ||
} |