Skip to content

Commit

Permalink
Add tooling and documentation to generate protos
Browse files Browse the repository at this point in the history
  • Loading branch information
johanstokking committed Dec 2, 2019
1 parent f5891c4 commit 083be49
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2019 The Things Industries B.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

SHELL = bash
GO = go
PROTOC = protoc

PROTO_PATH ?= ../..
VERSIONS ?= v1alpha1
GOPATH ?= $(shell $(GO) env GOPATH)

.PHONY: all
all: $(VERSIONS)

.PHONY: deps
deps:
$(GO) get github.com/gogo/protobuf/protoc-gen-gogofaster
$(GO) get google.golang.org/grpc

.PHONY: clean
clean:
rm -rf $(VERSIONS)

v%:
$(PROTOC) -I=$(GOPATH)/src -I=$(GOPATH)/src/github.com/gogo/protobuf/protobuf --gogofaster_out=plugins=grpc,\
Mgoogle/protobuf/any.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/duration.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/empty.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/struct.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/timestamp.proto=github.com/gogo/protobuf/types,\
Mgoogle/protobuf/wrappers.proto=github.com/gogo/protobuf/types:../../ \
--proto_path=$(PROTO_PATH) \
$(PROTO_PATH)/packetbroker/api/$@/*.proto

# vim: ft=make
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Packet Broker API for Go

`go-api` is the Packet Broker API for Go.

## Installing

Use `go get` to retrieve the Go API.

```bash
$ go get go.packetbroker.org/api
```

## Regenerating

The generated protos are checked in to this repository. You only need to regenerate the protos to incorporate changes coming from upstream.

To generate protos, [install the Protocol Compiler](https://github.com/protocolbuffers/protobuf#protocol-compiler-installation).

Before generating protos, get the dependencies:

```bash
$ make deps
```

Clean existing generated protos:

```bash
$ make clean
```

To generate protos, clone the [Packet Broker API repository](https://github.com/packetbroker/api).

If you clone the API repository in `../../packetbroker/api` relative to the path of this repository:

```bash
$ make
```

If you clone the API repository somewhere else, pass the import path where the `packetbroker/api` folder resides like this:

```bash
$ PROTO_PATH=<path> make
```

## License

The Go API is distributed under [Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0). See `LICENSE` for more information.

0 comments on commit 083be49

Please sign in to comment.