You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+56-15Lines changed: 56 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,36 +4,77 @@
4
4
5
5
Have all service definitions and code generated stubs for OpenKCM APIs.
6
6
7
-
## Generate protobuf code
7
+
## Pre-requisites
8
8
9
-
1.**Install `buf`:** If you haven't already, install `buf` by following the instructions on
10
-
the [Buf website](https://buf.build/docs/installation/).
11
-
You can install buf on macOS or Linux using Homebrew:
9
+
Several tools are required to generate the code:
12
10
13
-
```sh
14
-
brew install bufbuild/buf/buf
11
+
1.**`protoc compiler`**: see the instruction on the official [web site](https://protobuf.dev/installation) or install using homebrew `brew install protobuf`.
12
+
2.**`protoc-gen-go`**: install via `go install google.golang.org/protobuf/cmd/protoc-gen-go@latest`.
13
+
3.**`protoc-gen-go-grpc`**: install via `go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest`.
14
+
4.**`protofetch`**: download from the [releases page](https://github.com/coralogix/protofetch/releases/latest) of [the GitHub repository](https://github.com/coralogix/protofetch) or install via `cargo install protofetch` or `npm install -g @coralogix/protofetch`, or using any similar tool compatible with the npm registry.
15
+
16
+
## Optional tools
17
+
18
+
Optionally, the [`buf` CLI](https://github.com/bufbuild/buf) tool can be used to validate, detect breaking changes, and format `.proto` files:
19
+
20
+
-**`buf breaking --against https://github.com/openkcm/api-sdk.git#branch=main`**: detect breaking changes against the main branch of the remote repository.
21
+
-**`buf format -w`**: format `.proto` files.
22
+
-**`buf lint`**: lint `.proto` files.
23
+
24
+
## Makefile
25
+
26
+
There are several `make` targets defined in the `Makefile`:
27
+
28
+
-**`fetch-protos`**: download `.proto` dependencies using `protofetch`.
29
+
-**`generate`**: fetches `.proto` dependencies, formats `.proto` files, and generates Go code.
30
+
-**`install-tools`**: installs the tools (including optional) from the following sources: Homebrew, Go registry (via `go install`), NPM registry (via `npm install -g`). See the target definition for the details.
31
+
-**`validate`**: formats and lints `.proto` files, detects breaking changes.
32
+
33
+
For the rest `make` targets see `Makefile`.
34
+
35
+
## Dependencies
36
+
37
+
`.proto` dependencies are managed with the [`protofetch`](https://github.com/coralogix/protofetch) tool. This tool downloads `.proto` files from a specified location of a git repository and places them into the `vendor-proto` directory. The dependencies are specified in the `protofetch.toml` file.
38
+
39
+
For instance, a dependency on the [`protovalidate`](https://github.com/bufbuild/protovalidate) proto definitions can be specified as follow:
40
+
41
+
```toml
42
+
name = "github.com/openkcm/api-sdk"
43
+
description = "API proto definitions and Go generated code used in the openkcm project"
44
+
45
+
[protovalidate]
46
+
url = "github.com/bufbuild/protovalidate"
47
+
revision = "v1.1.1"
48
+
content_roots = ["/proto/protovalidate"]
49
+
allow_policies = ["buf/validate/*"]
15
50
```
16
51
17
-
2.**Generate code:** Use the ```sh make generate``` command to run the entire process.
52
+
In order to fetch dependencies, execute:
18
53
19
-
```sh
20
-
make generate
54
+
```sh
55
+
$ protofetch -o vendor-proto fetch
21
56
```
22
57
23
-
---
58
+
## Generate Go code from the .proto definitions
59
+
60
+
The code can be generated with executing the following Make target
61
+
62
+
```sh
63
+
$ make generate
64
+
```
24
65
25
66
## Using a specific branch
26
67
27
68
Ensure that the GOPRIVATE environment variable is set up:
28
69
29
-
```sh
30
-
go env -w GOPRIVATE="github.com/*"
31
-
```
70
+
```sh
71
+
$ go env -w GOPRIVATE="github.com/openkcm/*"
72
+
```
32
73
33
74
To use a specific branch of a repository in your Go project, you can use the `go get` command with the branch name.
34
75
Here's an example:
35
76
36
-
> go get github.com/openkcm/api-sdk/proto/kms/api/cmk/registry/system/v1@<branch-name>
77
+
> go get github.com/openkcm/api-sdk/proto/kms/api/cmk/registry/system/v1@\<branch-name\>
37
78
38
79
To switch back to the default branch, follow these steps:
39
80
@@ -44,7 +85,7 @@ To switch back to the default branch, follow these steps:
0 commit comments