Files
backstage/proto/README.md
T
Bilawal Hameed 18186f6c4b Updated docs
2020-02-06 10:18:24 +01:00

2.3 KiB

Backstage proto

Collection of all Backstage protobuf definitions.

Usage

Managed with Prototool, install instructions at https://github.com/uber/prototool/blob/dev/docs/install.md

Install Dependencies

Prototool

$ brew install prototool

protoc-gen-go

This will enable code generation in Go for interacting with gRPC-Web. You will need to have protoc-gen-go available in your path. You can find out more information here: https://github.com/golang/protobuf

$ go get -u github.com/golang/protobuf/protoc-gen-go
$ protoc-gen-go # should now be available in your path providing you GOPATH + GOBIN paths are setup correctly.

protoc-gen-ts

This will enable code generation in TypeScript for interacting with gRPC-Web. From the root, you will need to run Yarn in the frontend folder:

$ yarn --cwd ./frontend install

After this, you should be all set!

Generating Code

To generate the Protobuf definitions in Go and TypeScript, run the following command from the root with Prototool:

$ prototool generate ./proto

This will generate the respective "generated" files in the following folders:

  • backend/proto
  • frontend/packages/proto/src/generated

All generated code related to Protocol Buffers should be checked in to the repository.

Code Examples

Import using Go

This is what you'll need to use for development in any of the backend services.

package spotify.backstage.identity.v1;

func main() {
  identityv1.NewInventoryClient(nil)
}

Import using TypeScript

This is what you'll need to use for development in any of the frontend services. Firstly, ensure this line is in your package.json within the frontend/ folder:

"dependencies": {
  "@backstage/protobuf-definitions": "0.0.0",
  ...
}

Next, you can use them in your Yarn Workspaces package using the following:

import { IdentityClient } from "@backstage/protocol-definitions/generated/identity/v1/identity_pb_service";

const client = new IdentityClient("http://localhost:8080");
// const req = new GetUserRequest();
// req.setUsername("johndoe");
// client.getUser(req, (err, user) => {
//   /* ... */
// });