-
Notifications
You must be signed in to change notification settings - Fork 3
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
eb0f9be
commit 84acab9
Showing
7 changed files
with
228 additions
and
191 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
examples/rust/target/**/* | ||
**/.env |
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
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,94 @@ | ||
# Sift Protobuf Installation for Go | ||
|
||
Before proceeding with installation, you will need to ensure that you have the [buf CLI](https://buf.build/docs/installation) installed. | ||
|
||
If `$ which buf` generates a path to the executable, you may proceed to the installation steps. | ||
|
||
To install Sift protobufs in your project: | ||
|
||
1. Clone this repository onto your local machine and `cd` into it: | ||
|
||
```bash | ||
$ git clone https://github.com/sift-stack/sift | ||
$ cd sift | ||
``` | ||
|
||
2. Assuming the path to the root of your Go project is `$PROJECT_DIR`, run the following command in the `sift` directory that you just cloned: | ||
|
||
```bash | ||
$ buf export protos --output=$PROJECT_DIR/protos --config protos/buf.yaml | ||
``` | ||
|
||
The Sift protos can and its imports can now be found in your `$PROJECT_DIR/protos` directory. | ||
|
||
3. Copy the `buf` template for Go to your project directory: | ||
|
||
```bash | ||
$ cp buf_templates/buf.gen.go.yaml $PROJECT_DIR/buf.gen.yaml | ||
``` | ||
|
||
4. `cd` into your Go project at `$PROJECT_DIR`. | ||
|
||
5. Once inside of your Go project, you'll need to modify the `managed.enabled.go_package_prefix.default` value of your `buf.gen.yaml` file to | ||
have the package prefix named after your Go module. If our Go module's name, for example, is `github.com/example_project`, then change the `buf.gen.yaml` to `github.com/example_project/gen/protos/go`. Your | ||
`buf.gen.yaml` should now look like the following: | ||
|
||
```yaml | ||
version: v1 | ||
managed: | ||
enabled: true | ||
go_package_prefix: | ||
default: "github.com/example_project/gen/protos/go" | ||
plugins: | ||
- plugin: buf.build/protocolbuffers/go:v1.28.1 | ||
out: gen/protos/go | ||
opt: paths=source_relative | ||
- plugin: go-vtproto | ||
out: gen/protos/go | ||
opt: paths=source_relative | ||
- plugin: buf.build/grpc-ecosystem/gateway:v2.16.2 | ||
out: gen/protos/go | ||
opt: paths=source_relative | ||
``` | ||
Refer to your `go.mod` file for the name of your Go module. | ||
|
||
6. Inside of the root of your project directory you may now compile your protobufs: | ||
|
||
```bash | ||
$ buf generate protos | ||
``` | ||
|
||
Your project up to this point should look like the following (full depth not shown): | ||
|
||
``` | ||
example_project | ||
├─ buf.gen.yaml | ||
├─ gen | ||
│ └─ protos | ||
│ └─ go | ||
├─ go.sum | ||
├─ go.mod | ||
└─ protos | ||
├─ protoc-gen-openapiv2 | ||
│ └─ options | ||
│ └─ api | ||
└─ sift | ||
├─ runs | ||
├─ notifications | ||
├─ annotations | ||
├─ users | ||
├─ common | ||
├─ assets | ||
├─ tags | ||
└─ annotation_logs | ||
``` | ||
|
||
7. Install any dependencies you might be missing that the generated code requires: | ||
|
||
```bash | ||
$ go get -d ./... | ||
``` | ||
|
||
8. Now your project should be ready to use the generated Go code to interact with Sift's gRPC API. Please refer to the [example code](/examples/go) for usage. |
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,106 @@ | ||
# Sift Protobuf Installation for Rust | ||
|
||
Before proceeding with installation, you will need to ensure that you have the [buf CLI](https://buf.build/docs/installation) installed. | ||
|
||
If `$ which buf` generates a path to the executable, you may proceed to the installation steps. | ||
|
||
To install Sift protobufs in your project: | ||
|
||
1. Clone this repository onto your local machine and `cd` into it: | ||
|
||
```bash | ||
$ git clone https://github.com/sift-stack/sift | ||
$ cd sift | ||
``` | ||
|
||
2. Assuming the path to the root of your Rust project is `$PROJECT_DIR`, run the following command in the `sift` directory that you just cloned: | ||
|
||
```bash | ||
$ buf export protos --output=$PROJECT_DIR/protos --config protos/buf.yaml | ||
``` | ||
|
||
The Sift protos can and its imports can now be found in your `$PROJECT_DIR/protos` directory. | ||
|
||
3. Copy the `buf` template for Rust to your project directory: | ||
|
||
```bash | ||
$ cp buf_templates/buf.gen.go.yaml $PROJECT_DIR/buf.gen.yaml | ||
``` | ||
|
||
4. `cd` into your Rust project at `$PROJECT_DIR`. | ||
|
||
5. Once inside of your Rust project, declare a module called `gen` in your `main.rs` (unless you're crate is a lib-crate) and create a `src/gen/mod.rs` file. | ||
|
||
```rust | ||
// main.go | ||
|
||
/// Sift generated code | ||
mod gen; | ||
``` | ||
|
||
Refer to the `buf.gen.yaml` in your project root if you need to modify the output path for the compiled protos. | ||
|
||
|
||
6. Inside of the root of your project directory you may now compile your protobufs: | ||
|
||
```bash | ||
$ buf generate protos | ||
``` | ||
|
||
Your project up to this point should look like the following (full depth not shown): | ||
|
||
``` | ||
example_project | ||
├─ src | ||
│ ├─ main.rs | ||
│ └─ gen | ||
│ ├─ sift.common.type.v1.rs | ||
│ ├─ sift.runs.v2.rs | ||
│ ├─ sift.annotation_logs.v1.rs | ||
│ ├─ sift.runs.v2.tonic.rs | ||
│ ├─ sift.users.v2.rs | ||
│ ├─ mod.rs | ||
│ ├─ sift.tags.v1.rs | ||
│ ├─ sift.assets.v1.tonic.rs | ||
│ ├─ sift.assets.v1.rs | ||
│ ├─ sift.notifications.v1.tonic.rs | ||
│ ├─ sift.users.v2.tonic.rs | ||
│ ├─ sift.annotation_logs.v1.tonic.rs | ||
│ ├─ grpc.gateway.protoc_gen_openapiv2.options.rs | ||
│ ├─ sift.notifications.v1.rs | ||
│ ├─ sift.annotations.v1.tonic.rs | ||
│ ├─ google.api.rs | ||
│ └─ sift.annotations.v1.rs | ||
├─ buf.gen.yaml | ||
├─ README.md | ||
├─ Cargo.lock | ||
└─ Cargo.toml | ||
2 directories, 22 files | ||
``` | ||
|
||
7. Ensure you have the following dependencies installed: | ||
|
||
```toml | ||
[package] | ||
name = "sift_cli" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
async-trait = "0.1.79" | ||
prost = "0.12.4" | ||
prost-types = "0.12.4" | ||
tonic = { version = "0.11.0", features = ["tls", "tls-roots", "tls-webpki-roots"] } | ||
``` | ||
|
||
8. Declare the modules that will import the generated code in your `src/gen/mod.rs`. For example, we wish to use the generated `annotations` code for this example: | ||
|
||
```rust | ||
#[path = "sift.annotations.v1.rs"] | ||
pub mod annotations; | ||
``` | ||
|
||
9. Now your project should be ready to use the generated Rust code to interact with Sift's gRPC API. Please refer to the [example code](/examples/rust/) for usage. |
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
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,96 +1,22 @@ | ||
# Sift Go Example | ||
|
||
Before proceeding with installation, you will need to ensure that you have the [buf CLI](https://buf.build/docs/installation) installed. | ||
To run this example ensure that you have Go and the [buf CLI](https://buf.build/docs/installation) installed. | ||
|
||
If `$ which buf` generates a path to the executable, you may proceed to the installation steps. | ||
|
||
To install Sift protobufs in your project: | ||
|
||
1. Clone this repository onto your local machine and `cd` into it: | ||
|
||
```bash | ||
$ git clone https://github.com/sift-stack/sift | ||
$ cd sift | ||
``` | ||
|
||
2. Assuming the path to the root of your Go project is `$PROJECT_DIR`, run the following command in the `sift` directory that you just cloned: | ||
|
||
```bash | ||
$ buf export protos --output=$PROJECT_DIR/protos --config protos/buf.yaml | ||
``` | ||
|
||
The Sift protos can and its imports can now be found in your `$PROJECT_DIR/protos` directory. | ||
|
||
3. Copy the `buf` template for Go to your project directory: | ||
|
||
```bash | ||
$ cp buf_templates/buf.gen.go.yaml $PROJECT_DIR/buf.gen.yaml | ||
``` | ||
|
||
4. `cd` into your Go project at `$PROJECT_DIR`. | ||
|
||
5. Once inside of your Go project, you'll need to modify the `managed.enabled.go_package_prefix.default` value of your `buf.gen.yaml` file to | ||
have the package prefix named after your Go module. If our Go module's name, for example, is `github.com/sift-go-cli`, then change the `buf.gen.yaml` to `github.com/sift-go-cli/gen/protos/go`. Your | ||
`buf.gen.yaml` should now look like the following: | ||
|
||
```yaml | ||
version: v1 | ||
managed: | ||
enabled: true | ||
go_package_prefix: | ||
default: "github.com/sift-go-cli/gen/protos/go" | ||
plugins: | ||
- plugin: buf.build/protocolbuffers/go:v1.28.1 | ||
out: gen/protos/go | ||
opt: paths=source_relative | ||
- plugin: go-vtproto | ||
out: gen/protos/go | ||
opt: paths=source_relative | ||
- plugin: buf.build/grpc-ecosystem/gateway:v2.16.2 | ||
out: gen/protos/go | ||
opt: paths=source_relative | ||
``` | ||
Refer to your `go.mod` file for the name of your Go module. | ||
|
||
6. Inside of the root of your project directory you may now compile your protobufs: | ||
Once those are installed and your working directory is this project's root, compile the protobufs: | ||
|
||
```bash | ||
$ buf generate protos | ||
``` | ||
|
||
Your project up to this point should look like the following (full depth not shown): | ||
Install dependencies: | ||
|
||
``` | ||
sift-go-cli | ||
├─ buf.gen.yaml | ||
├─ gen | ||
│ └─ protos | ||
│ └─ go | ||
├─ go.sum | ||
├─ go.mod | ||
└─ protos | ||
├─ protoc-gen-openapiv2 | ||
│ └─ options | ||
│ └─ api | ||
└─ sift | ||
├─ runs | ||
├─ notifications | ||
├─ annotations | ||
├─ users | ||
├─ common | ||
├─ assets | ||
├─ tags | ||
└─ annotation_logs | ||
```bash | ||
$ go get -d ./... | ||
``` | ||
|
||
7. Install any dependencies you might be missing that the generated code requires: | ||
Now execute the program by providing the partial string of the annotations you wish to query. In the following example | ||
we'll be querying for all annotations whose name matches the `voltage` substring in a case-insensitive manner. | ||
|
||
```bash | ||
$ go get -d ./... | ||
$ go run . voltage | ||
``` | ||
|
||
8. Now your project should be ready to use the generated Go code to interact with Sift's gRPC API. Please refer to the example code for usage. | ||
If you are cloning the example repository, be sure to `$ cp .example.env .env` and set the appropriate variables. Comments in the `.example.env` files | ||
may prove useful. |
Oops, something went wrong.