This is the main Resonate User/Track API written in Go, still WIP and not yet in production. If you're looking for the API that is currently running with http://beta.resonate.is, please check its documentation here.
The User/Track API uses Twirp, a RPC framework for service-to-service communication emphasizing simplicity and minimalism. Learn more about Twirp at its website. It also uses go-pg PostgreSQL ORM. Its structure is based on the Twirp starter kit Twisk.
The project structure mostly follows THIS example repository and Twirp best practices, except for the services that live in internal/server/<service>.
- Go 1.7 or higher.
- PostgreSQL 9.4 or higher.
- Create user and database as follow (as found in the local config file in
./conf.local.yaml):
username = "resonate_dev_user"
password = "password"
dbname = "resonate_dev"
Add following postgres extensions: "hstore" and "uuid-ossp"
From ./cmd/migration:
- Init migrations
$ go run *.go init- Run migrations
$ go run *.goDep is used as dependency management tool.
vendor/ folder contains project dependencies and should be in sync with Gopkg.toml and Gopkg.lock.
- Install Protocol Buffers v3,
the
protoccompiler that is used to auto-generate code. The simplest way to do this is to download pre-compiled binaries for your platform from here: https://github.com/google/protobuf/releases
It is also available in MacOS through Homebrew:
$ brew install protobuf- Install retool. It helps manage go tools like commands and linters.
protoc-gen-go and protoc-gen-twirp plugins were installed into
_toolsfolder using retool.
Build the generators and tool dependencies:
$ retool buildThen, to run the protoc command and autogenerate Go code for the server interface, make sure to prefix with retool do, for example:
$ retool do protoc --proto_path=$GOPATH/src:. --twirp_out=. --go_out=. ./rpc/user/service.protoFirst, put this repo into $GOPATH/src
Then, run the server
$ go run ./cmd/api/main.goAlternatively, you can build and run an executable binary
$ cd ./cmd/api/
$ go build
$ ./api-
Under
protofolder, create a new one named after your service. -
Define your proto file. If you are not familiar with Protobufs, you can read more about it here. You can use already existing proto files (eg
rpc/user/service.proto) as a template. -
Run
retool do protoc --proto_path=$GOPATH/src:. --twirp_out=. --go_out=. ./rpc/<service>/service.protowhere<service>is your new service name. -
Implement the service interface from
service.twirp.goininternal/server/tenant. -
Wire up everything in
cmd/api/main.go.
- Check out
doc/apifolder for API documentation. But we'll be transitioning to OpenAPI Specification and Swagger. doc/databasecontains autogenerated database documentation, using SchemaSpy. Opendoc/database/index.htmlin your browser to check it out.
We use Ginkgo and Gomega for testing.
You need to create the testing database and run migrations manually before running tests.
- Create user and database as follow:
username = "resonate_testing_user"
password = ""
dbname = "resonate_testing"
Add following extensions: "hstore" and "uuid-ossp" (TODO: add them on initial migration)
- Run migrations from
./cmd/migration
$ go run *.go init testing
$ go run *.go testing- Run tests
./internal/server/<service>
$ go testOr run all tests using ginkgo CLI from ./
$ ginkgo -r(see our projects for more details)
- Switch from API Blueprint to OpenAPI and autogenerated API documentation using SwaggerUI
- Implement logging interfaces for every service
- Add JWT based authentication and role-based access control (see
internal/iam) to existing services
Please check out the Contributing guide for guidelines about how to proceed.
We expect contributors to abide by our underlying code of conduct.