Skip to content

Commit

Permalink
docs: add docs for volo-http and refactor volo directories (#1125)
Browse files Browse the repository at this point in the history
  • Loading branch information
StellarisW authored Sep 10, 2024
1 parent 6235b19 commit da93d0f
Show file tree
Hide file tree
Showing 43 changed files with 2,832 additions and 178 deletions.
8 changes: 8 additions & 0 deletions content/en/docs/volo/cli/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
title: "Cli"
linkTitle: "Cli"
weight: 2
keywords: ["Rust", "Volo", "cli"]
description: "Volo-cli Usage"
---

126 changes: 126 additions & 0 deletions content/en/docs/volo/cli/getting-started/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
---
title: "Getting Started"
linkTitle: "Getting Started"
weight: 2
keywords: ["Volo", "cli", "Tutorial", "Install"]
description: "This document covers the preparation of the development environment, quick start and basic tutorials of Volo-HTTP."
---

Volo provides CLI tools of the same name, and it provide functions as follows:

1. Server-side scaffold generation

support generate HTTP or RPC server-side scaffold by IDL like Thrift, Protobuf

2. Stub management

3. Old version migration

## Part 1. Install Cli tool

```bash
cargo install volo-cli
```

Need rustc version >= 1.80.0

Then, we type:

```bash
volo help
```

and we can see the output as follows:

```plain
Usage: volo [OPTIONS] <COMMAND>
Commands:
init init your thrift or grpc project
http manage your http project
repo manage your repo
idl manage your idl
migrate migrate your config from old version
help Print this message or the help of the given subcommand(s)
Options:
-v, --verbose... Turn on the verbose mode.
-n, --entry-name <ENTRY_NAME> The entry name, defaults to 'default'. [default: default]
-h, --help Print help
-V, --version Print version
```

## Part 2. Generate RPC code

To create a RPC project, we need to write an IDL first. Let's take Thrift for example.


Create a new Thrift IDL in the project directory:

`vim idl/rpc_example.thrift`

```thrift
namespace rs volo.rpc.example
struct Item {
1: required i64 id,
2: required string title,
3: required string content,
10: optional map<string, string> extra,
}
struct GetItemRequest {
1: required i64 id,
}
struct GetItemResponse {
1: required Item item,
}
service ItemService {
GetItemResponse GetItem (1: GetItemRequest req),
}
```

Execute the following command:

`volo init volo-rpc-example idl/rpc_example.thrift`

At this point, our entire catalog is structured as follows:

```plain
.
├── Cargo.toml
├── idl
│ └── rpc_example.thrift
├── rust-toolchain.toml
├── src
│ ├── bin
│ │ └── server.rs
│ └── lib.rs
└── volo-gen
├── Cargo.toml
├── build.rs
├── src
│ └── lib.rs
└── volo.yml
```

## Part 2. Generate HTTP code

Execute the following command:

`volo http init volo-http-example`

At this point, our entire catalog is structured as follows:

```bash
$ tree
.
├── Cargo.toml
└── src
├── bin
│   └── server.rs
└── lib.rs
```
23 changes: 23 additions & 0 deletions content/en/docs/volo/cli/migrate/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
title: "Migrate"
linkTitle: "Migrate"
weight: 4
keywords: ["Volo", "cli", "Migrate"]
description: "Volo-Cli Migrate"
---

Migrating from an older version of `volo.yml` to the current version of `volo.yml`

```bash
Usage: volo migrate [OPTIONS]

Options:
-v, --verbose... Turn on the verbose mode.
-h, --help Print help
-V, --version Print version
```

## How to migrate?

1. Switch to the root directory of the project (where `volo.yml` is located).
2. Run the command `volo migrate`
2 changes: 1 addition & 1 deletion content/en/docs/volo/faq/_index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "FAQ"
linkTitle: "FAQ"
weight: 8
weight: 9
keywords: ["Volo", "FAQ", "volo-cli", "poll_ready"]
description: Answers to frequently asked questions.
---
Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/volo/guide/_index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Guide"
linkTitle: "Guide"
weight: 4
weight: 6
description: Project usage guide.
---
2 changes: 1 addition & 1 deletion content/en/docs/volo/motore/_index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Motore"
linkTitle: "Motore"
weight: 6
weight: 7
keywords: ["Motore", "AFIT", "RPITIT"]
Description: Motore is an async middleware abstraction powered by AFIT and RPITIT.
---
Expand Down
12 changes: 8 additions & 4 deletions content/en/docs/volo/overview/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ We have also created an organization [Volo-rs](http://github.com/volo-rs), any c

## Related Projects

1. [Volo-rs](http://github.com/volo-rs):The volo ecosystem which contains a lot of useful components.
2. [Pilota](https://github.com/cloudwego/pilota):A thrift and protobuf implementation in pure rust with high performance and extensibility.
3. [Motore](https://github.com/cloudwego/motore):Middleware abstraction layer powered by AFIT and RPITIT.
4. [Metainfo](https://github.com/cloudwego/metainfo):Transmissing metainfo across components.
- [Volo-rs](http://github.com/volo-rs):The volo ecosystem which contains a lot of useful components.
- [Pilota](https://github.com/cloudwego/pilota):A thrift and protobuf implementation in pure rust with high performance and extensibility.
- [Motore](https://github.com/cloudwego/motore):Middleware abstraction layer powered by AFIT and RPITIT.
- [Metainfo](https://github.com/cloudwego/metainfo):Transmissing metainfo across components.

## Related Articles

- [China's First Rust-based RPC Framework - Volo is Officially Open Source!](https://www.cloudwego.io/blog/2022/08/30/chinas-first-rust-based-rpc-framework-volo-is-officially-open-source/)
2 changes: 1 addition & 1 deletion content/en/docs/volo/pilota/_index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Pilota"
linkTitle: "Pilota"
weight: 7
weight: 8
keywords: ["Pilota", "Thrift", "Protobuf", "Plugin"]
Description: Pilota is a Thrift and Protobuf implementation in pure rust with high performance and extensibility.
---
Expand Down
2 changes: 1 addition & 1 deletion content/en/docs/volo/volo-grpc/_index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: "Volo-gRPC"
linkTitle: "Volo-gRPC"
weight: 3
weight: 5
keywords: ["Volo", "gRPC", "Getting Started", "Guidelines"]
description: "CLI tool installation, quick start and basic tutorials for Volo-gRPC."
---
48 changes: 7 additions & 41 deletions content/en/docs/volo/volo-grpc/getting-started/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,13 @@ keywords: ["Volo", "gRPC", "Tutorial", "Install"]
description: "This document covers the preparation of the development environment, quick start and basic tutorials of Volo-gRPC."
---

## Part 1. Install the CLI Tool

Volo provides CLI tools of the same name for initializing projects, managing IDLs, and more.

```bash
cargo install volo-cli
```

> Make sure that the Rust version is >= 1.75.0
Then run:

```bash
volo help
```

You should see something like the following:

```bash
USAGE:
volo [OPTIONS] <SUBCOMMAND>

OPTIONS:
-h, --help Print help information
-n, --entry-name <ENTRY_NAME> The entry name, defaults to 'default'. [default: default]
-v, --verbose Turn on the verbose mode.
-V, --version Print version information

SUBCOMMANDS:
help Print this message or the help of the given subcommand(s)
idl manage your idl
init init your project
```

## Part 2. Create a gRPC Server
## Part 1. Create a gRPC Server

Volo-gRPC is an RPC framework so that the bottom layer requires two major functions: Serialization and Transport.

IDL is short for `Interface Definition Language`.

### 2.1 Why IDL
### 1.1 Why IDL

If we want to do RPC, we need to know what interface is for the server, what parameters to pass, and what the return value is,
just like two people talking to each other, we need to make sure we are speaking the same language and doing the same thing.
Expand All @@ -55,7 +21,7 @@ At this time, we need to use IDL to specify the protocol for both sides, just li

Protobuf IDL is a full-stack RPC solution for cross-language, the specific syntax can be seen in [protocol-buffers/docs/proto3](https://developers.google.com/protocol-buffers/docs/proto3).

### 2.2 Write IDL
### 1.2 Write IDL

To create a gRPC project, we need to write a protobuf IDL first.

Expand Down Expand Up @@ -171,7 +137,7 @@ cargo run --bin server

At this point, we have our server running!

## Part 3. Create a Client
## Part 2. Create a Client

In the previous section, we wrote a server, now let's write a client and call the server.

Expand Down Expand Up @@ -255,7 +221,7 @@ Finally, we go back to the current directory and execute the following command,
cargo run --bin client
```

## Part 4. Add a Middleware
## Part 3. Add a Middleware

Next, let's look at how to add middleware to Volo.

Expand Down Expand Up @@ -320,7 +286,7 @@ Server::new()

At this point, it prints out how long the request took at the INFO log level.

## Part 5. What's Next?
## Part 4. What's Next?

Congratulations, you've read this far! At this point, we've basically learned how to use Volo, and we're ready to use Volo to kick off our Rust journey

Expand All @@ -333,7 +299,7 @@ If there is a dire lack of components, you are welcomed to raise an issue in: ht
In the meantime, welcome to join our Lark user group and share your experience with us about Volo.

<div align="center">
<img src="/img/docs/feishu_group_volo.png" width = "400" alt="Volo_feishu" />
<img src="/img/docs/feishu_group_volo.png" width="400" alt="Volo_feishu" />
</div>
<br/><br/>

Expand Down
7 changes: 7 additions & 0 deletions content/en/docs/volo/volo-http/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
title: "Volo-HTTP"
linkTitle: "Volo-HTTP"
weight: 3
keywords: ["Volo", "HTTP", "Getting started", "Tutorials"]
description: "Volo-HTTP Tutorials。"
---
Loading

0 comments on commit da93d0f

Please sign in to comment.