server

module
v0.0.0-...-d14928a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2021 License: MIT

README

Summary

Resources related to backend services that support the Mono iOS and Android clients can be found here.

Structure

server
├── cmd
│   └── dummy
│       ├── BUILD.bazel
│       └── main.go
├── pkg
│   └── dummy
│       └── v1
│           ├── BUILD.bazel
│           └── dummy.proto
├── Dockerfile
├── Dockerfile.test
├── BUILD
├── WORKSPACE
├── tools.go
├── go.mod
└── go.sum
  • cmd

    cmd contains service entry points in the main.go. Each directory in cmd maps to a similarly named service.

  • pkg

    pkg contains shared code, libraries, and service definitions. In keeping with the buf styleguide, protobuf messages and services are in versioned packages.

Getting started

With the introduction of the Bazel system, getting up and running is fairly simple. The first of two requirements is that bazel be installed like so:

$ brew install bazel

Next, install docker manually by following the linked steps.

Existing services

An existing service can be brought up individually using the

$ bazel run //cmd/[SERVICE]:[SERVICE]

command. To bring up all existing services in containers, just run

$ make coldstart
New services

Start by creating a versioned service definition in a package named after the service (i.e. [SERVICE]/v1/[SERVICE].proto). Be sure to follow the buf styleguide when declaring RPCs and messages. This versioned package should be under pkg.

Then, create a BUILD.bazel that has instructions for how to build the service. The BUILD.bazel for the dummer service is a good example of a service with both external and local dependencies. The dummy service contains an example for a service with no local dependencies.

Finally, create a new service entrypoint and BUILD.bazel file in a package named after the service under cmd (i.e. cmd/[SERVICE]/main.go). Once service endpoints are implemented, use

$ bazel run //cmd/[SERVICE]:SERVICE

to bring up the service locally. Also, be sure to add the service configuration to the docker-compose.yml file so that the new service can be brought up in a container.

[Deprecated] Getting started

It's assumed that the Go environment ($GOPATH and $GOBIN) have been correctly setup. In order to get started, clone this repo and install the following tools:

  • protoc - This is the protocol buffer compiler
  • protoc-gen-go - This is a compiler plugin to protoc that enables the compiler to generate Go code
  • grpc-gateway - This compiler plugin to protoc generates a reverse-proxy server which translates a RESTful HTTP API into gRPC
$ brew install protobuf
$ GO111MODULE=on go get github.com/golang/protobuf/protoc-gen-go
$ GO111MODULE=on go get github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway@v1.14.7
  • docker - This is a containerization tool that services will run in

    Install docker manually by following the steps linked above

  • googleapis - This repo provides some helpful tools and .proto files for transcoding HTTP/JSON to gRPC

$ go get github.com/googleapis/googleapis@v0.0.0-20200814034631-3a54e988edcb

After these steps, you should be able to bring up existing services using make start and make stop.

To define a new service, write a definition for that service i.e. [NAME].proto in idl and create an entry point i.e. main.go in a new directory under cmd/[NAME]. Then, using make proto SERVICE="[NAME]" where SERVICE is the name of the service's definition and entry point i.e. dummy, generate the service stubs. These can be found in pkg/[NAME]_gen. The final step is to implement the business logic in the entry point that was created earlier.

Helpful notes

Bazel protobuf docs

Bazel gazelle docs

Bazel go docs

Bazel go + protobuf docs

gRPC gateway docs

Buf docs

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL