diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9f03584..481bd43 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -67,14 +67,14 @@ jobs: - name: Prepare the dist folder run: | mkdir -p "${GITHUB_WORKSPACE}/dist/" - cp "${GITHUB_WORKSPACE}/bazel-bin/services/a/service-a" "${GITHUB_WORKSPACE}/dist/" - cp "${GITHUB_WORKSPACE}/bazel-bin/services/b/service-b" "${GITHUB_WORKSPACE}/dist/" + cp "${GITHUB_WORKSPACE}/bazel-bin/services/servicea/servicea" "${GITHUB_WORKSPACE}/dist/" + cp "${GITHUB_WORKSPACE}/bazel-bin/services/serviceb/serviceb" "${GITHUB_WORKSPACE}/dist/" - name: Compress run: | tar czvf ${{matrix.name}}.tar.gz --directory "${GITHUB_WORKSPACE}/dist/" \ - service-a \ - service-b + servicea \ + serviceb - name: Upload the build as an artifact uses: actions/upload-artifact@v3 diff --git a/BUILD.bazel b/BUILD.bazel index 28196ee..123de9d 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -16,5 +16,3 @@ gazelle( # make sure that others can import either using the import or go_default_library naming conventions # gazelle:go_naming_convention import_alias - -# gazelle:proto disable_global diff --git a/README.md b/README.md index daf8145..c05ee49 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,97 @@ # go-bazel -A sample scaffold golang + Bazel mono repository. +A Bazel scaffold template for `golang` / `protobuf+grpc` mono repository. ## Features -- Multi microservices in the mono repo +- Multi `golang` microservices in the mono repo - Single build pipeline +- Shared `golang` library +- Shared `grpc/protobuf` library - Automatic release GitHub workflow action - macOS and Linux builds -## CLI +## A hypothetical setup -```sh -bazel run //:gazelle -``` +- A cli `ServiceA` calling `ServiceB` grpc method `Sum(int32, inte32)` +- A `ServiceB` serving the `Sum` method over grpc. -```sh -bazel run //:gazelle-update-repos -``` +### Step 1: Install Bazel -```sh -bazel test //... --test_output=errors --nocache_test_results -``` +- **macOS**: [https://bazel.build/install/os-x](https://bazel.build/install/os-x) +- **Ubuntu**: [https://bazel.build/install/ubuntu](https://bazel.build/install/ubuntu) + +### Step 2: Build it + +Run the complete build pipeline using: ```sh bazel build //... ``` +> **Note:** The first build will take a moment. No worries, you will see the Bazel mono repo benefits later. + +### Step 3: Run to see the result + +In one terminal, run the grpc serving `ServiceB`: + ```sh -bazel run services/a +bazel run services/serviceb :42042 ``` +In another terminal, run the client `ServiceA`: + ```sh -bazel run services/b +bazel run services/servicea :42042 ``` + +You should see the result. Protobuf + grpc built, services binaries built as well. +The built binaries are in the `/bazel-bin` directory in their respective sub +directories. + +## Protobuf/grpc caveats + +There is a little caveat with proto when using Bazel. The `golang` generated proto +files are in the `bazel-bin` build folder (as they are result of the build, not a +source). So they are not accessible to your IDE. [There is an official issue](https://github.com/bazelbuild/rules_go/issues/512). +Until solved, the workaround is: + +- For every proto service: +- Run Bazel to generate the proto `golang` implementation: + + ```sh + bazel run //proto/[service] + ``` + +- Manually copy generated implementation back to the `proto/[service]` directory: + + ```sh + cp ./bazel-bin/proto/[service]/[service]_go_proto_/github.com/kikotxyz/babykktd/proto/[service]/*.pb.go ./proto/[service]/ + ``` + +- Also, you have to exclude the copied file from the Bazel build. Create file `/proto/[service]/.bazelignore` and put there all generated `[filename].pb.go` files. + +> **Note:** Of course, this process can be automated. + +## Additonal commands + +- Build `BUILD.bazel` build files using [Gazelle](https://github.com/bazelbuild/bazel-gazelle): + ```sh + bazel run //:gazelle + ``` +- Update Gazelle `golang` dependencies using: + ```sh + bazel run //:gazelle-update-repos + ``` +- Test whole pipeline using: + ```sh + bazel test //... + ``` + +--- + +## Additional resources + +- [Bazel official website](https://bazel.build/) +- [Bazel at GitHub](https://github.com/bazelbuild/bazel) +- [Gazelle at GitHub](https://github.com/bazelbuild/bazel-gazelle) diff --git a/WORKSPACE b/WORKSPACE index b4e4fda..91aceb8 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -20,8 +20,19 @@ http_archive( ], ) +http_archive( + name = "com_google_protobuf", + sha256 = "d0f5f605d0d656007ce6c8b5a82df3037e1d8fe8b121ed42e536f569dec16113", + strip_prefix = "protobuf-3.14.0", + urls = [ + "https://mirror.bazel.build/github.com/protocolbuffers/protobuf/archive/v3.14.0.tar.gz", + "https://github.com/protocolbuffers/protobuf/archive/v3.14.0.tar.gz", + ], +) + load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies") +load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps") ############################################################ # Define your own dependencies here using go_repository. @@ -41,3 +52,5 @@ go_rules_dependencies() go_register_toolchains(version = "1.19.1") gazelle_dependencies() + +protobuf_deps() diff --git a/deps.bzl b/deps.bzl index eae0cc8..ee913ef 100644 --- a/deps.bzl +++ b/deps.bzl @@ -1,6 +1,14 @@ load("@bazel_gazelle//:deps.bzl", "go_repository") def go_dependencies(): + go_repository( + name = "co_honnef_go_tools", + build_file_proto_mode = "disable_global", + importpath = "honnef.co/go/tools", + sum = "h1:/hemPrYIhOhy8zYrNj+069zDB68us2sMGsfkFJO0iZs=", + version = "v0.0.0-20190523083050-ea95bdfd59fc", + ) + go_repository( name = "com_github_benbjohnson_clock", build_file_proto_mode = "disable_global", @@ -8,6 +16,49 @@ def go_dependencies(): sum = "h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=", version = "v1.1.0", ) + go_repository( + name = "com_github_burntsushi_toml", + build_file_proto_mode = "disable_global", + importpath = "github.com/BurntSushi/toml", + sum = "h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=", + version = "v0.3.1", + ) + go_repository( + name = "com_github_census_instrumentation_opencensus_proto", + build_file_proto_mode = "disable_global", + importpath = "github.com/census-instrumentation/opencensus-proto", + sum = "h1:glEXhBS5PSLLv4IXzLA5yPRVX4bilULVyxxbrfOtDAk=", + version = "v0.2.1", + ) + go_repository( + name = "com_github_cespare_xxhash_v2", + build_file_proto_mode = "disable_global", + importpath = "github.com/cespare/xxhash/v2", + sum = "h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY=", + version = "v2.1.1", + ) + go_repository( + name = "com_github_client9_misspell", + build_file_proto_mode = "disable_global", + importpath = "github.com/client9/misspell", + sum = "h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=", + version = "v0.3.4", + ) + go_repository( + name = "com_github_cncf_udpa_go", + build_file_proto_mode = "disable_global", + importpath = "github.com/cncf/udpa/go", + sum = "h1:hzAQntlaYRkVSFEfj9OTWlVV1H155FMD8BTKktLv0QI=", + version = "v0.0.0-20210930031921-04548b0d99d4", + ) + go_repository( + name = "com_github_cncf_xds_go", + build_file_proto_mode = "disable_global", + importpath = "github.com/cncf/xds/go", + sum = "h1:zH8ljVhhq7yC0MIeUL/IviMtY8hx2mK8cN9wEYb8ggw=", + version = "v0.0.0-20211011173535-cb28da3451f1", + ) + go_repository( name = "com_github_davecgh_go_spew", build_file_proto_mode = "disable_global", @@ -15,6 +66,56 @@ def go_dependencies(): sum = "h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=", version = "v1.1.1", ) + go_repository( + name = "com_github_envoyproxy_go_control_plane", + build_file_proto_mode = "disable_global", + importpath = "github.com/envoyproxy/go-control-plane", + sum = "h1:xvqufLtNVwAhN8NMyWklVgxnWohi+wtMGQMhtxexlm0=", + version = "v0.10.2-0.20220325020618-49ff273808a1", + ) + go_repository( + name = "com_github_envoyproxy_protoc_gen_validate", + build_file_proto_mode = "disable_global", + importpath = "github.com/envoyproxy/protoc-gen-validate", + sum = "h1:EQciDnbrYxy13PgWoY8AqoxGiPrpgBZ1R8UNe3ddc+A=", + version = "v0.1.0", + ) + go_repository( + name = "com_github_golang_glog", + build_file_proto_mode = "disable_global", + importpath = "github.com/golang/glog", + sum = "h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=", + version = "v0.0.0-20160126235308-23def4e6c14b", + ) + go_repository( + name = "com_github_golang_mock", + build_file_proto_mode = "disable_global", + importpath = "github.com/golang/mock", + sum = "h1:G5FRp8JnTd7RQH5kemVNlMeyXQAztQ3mOWV95KxsXH8=", + version = "v1.1.1", + ) + go_repository( + name = "com_github_golang_protobuf", + build_file_proto_mode = "disable_global", + importpath = "github.com/golang/protobuf", + sum = "h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=", + version = "v1.5.2", + ) + go_repository( + name = "com_github_google_go_cmp", + build_file_proto_mode = "disable_global", + importpath = "github.com/google/go-cmp", + sum = "h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=", + version = "v0.5.6", + ) + go_repository( + name = "com_github_google_uuid", + build_file_proto_mode = "disable_global", + importpath = "github.com/google/uuid", + sum = "h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y=", + version = "v1.1.2", + ) + go_repository( name = "com_github_pkg_errors", build_file_proto_mode = "disable_global", @@ -29,6 +130,14 @@ def go_dependencies(): sum = "h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=", version = "v1.0.0", ) + go_repository( + name = "com_github_prometheus_client_model", + build_file_proto_mode = "disable_global", + importpath = "github.com/prometheus/client_model", + sum = "h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM=", + version = "v0.0.0-20190812154241-14fe0d1b01d4", + ) + go_repository( name = "com_github_stretchr_objx", build_file_proto_mode = "disable_global", @@ -43,6 +152,14 @@ def go_dependencies(): sum = "h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=", version = "v1.8.0", ) + go_repository( + name = "com_google_cloud_go", + build_file_proto_mode = "disable_global", + importpath = "cloud.google.com/go", + sum = "h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg=", + version = "v0.34.0", + ) + go_repository( name = "in_gopkg_check_v1", build_file_proto_mode = "disable_global", @@ -57,6 +174,98 @@ def go_dependencies(): sum = "h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=", version = "v3.0.1", ) + go_repository( + name = "org_golang_google_appengine", + build_file_proto_mode = "disable_global", + importpath = "google.golang.org/appengine", + sum = "h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=", + version = "v1.4.0", + ) + go_repository( + name = "org_golang_google_genproto", + build_file_proto_mode = "disable_global", + importpath = "google.golang.org/genproto", + sum = "h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY=", + version = "v0.0.0-20200526211855-cb27e3aa2013", + ) + go_repository( + name = "org_golang_google_grpc", + build_file_proto_mode = "disable_global", + importpath = "google.golang.org/grpc", + sum = "h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw=", + version = "v1.49.0", + ) + go_repository( + name = "org_golang_google_protobuf", + build_file_proto_mode = "disable_global", + importpath = "google.golang.org/protobuf", + sum = "h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=", + version = "v1.28.1", + ) + go_repository( + name = "org_golang_x_crypto", + build_file_proto_mode = "disable_global", + importpath = "golang.org/x/crypto", + sum = "h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=", + version = "v0.0.0-20200622213623-75b288015ac9", + ) + go_repository( + name = "org_golang_x_exp", + build_file_proto_mode = "disable_global", + importpath = "golang.org/x/exp", + sum = "h1:c2HOrn5iMezYjSlGPncknSEr/8x5LELb/ilJbXi9DEA=", + version = "v0.0.0-20190121172915-509febef88a4", + ) + go_repository( + name = "org_golang_x_lint", + build_file_proto_mode = "disable_global", + importpath = "golang.org/x/lint", + sum = "h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0=", + version = "v0.0.0-20190313153728-d0100b6bd8b3", + ) + go_repository( + name = "org_golang_x_net", + build_file_proto_mode = "disable_global", + importpath = "golang.org/x/net", + sum = "h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI=", + version = "v0.0.0-20201021035429-f5854403a974", + ) + go_repository( + name = "org_golang_x_oauth2", + build_file_proto_mode = "disable_global", + importpath = "golang.org/x/oauth2", + sum = "h1:TzXSXBo42m9gQenoE3b9BGiEpg5IG2JkU5FkPIawgtw=", + version = "v0.0.0-20200107190931-bf48bf16ab8d", + ) + go_repository( + name = "org_golang_x_sync", + build_file_proto_mode = "disable_global", + importpath = "golang.org/x/sync", + sum = "h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=", + version = "v0.0.0-20190423024810-112230192c58", + ) + go_repository( + name = "org_golang_x_sys", + build_file_proto_mode = "disable_global", + importpath = "golang.org/x/sys", + sum = "h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k=", + version = "v0.0.0-20210119212857-b64e53b001e4", + ) + go_repository( + name = "org_golang_x_text", + build_file_proto_mode = "disable_global", + importpath = "golang.org/x/text", + sum = "h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=", + version = "v0.3.3", + ) + go_repository( + name = "org_golang_x_tools", + build_file_proto_mode = "disable_global", + importpath = "golang.org/x/tools", + sum = "h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A=", + version = "v0.0.0-20190524140312-2c0ae7006135", + ) + go_repository( name = "org_uber_go_atomic", build_file_proto_mode = "disable_global", diff --git a/go.mod b/go.mod index d0c7c8e..f709a90 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,18 @@ module github.com/jankremlacek/go-bazel go 1.19 -require go.uber.org/zap v1.23.0 +require ( + go.uber.org/zap v1.23.0 + google.golang.org/grpc v1.49.0 + google.golang.org/protobuf v1.28.1 +) require ( + github.com/golang/protobuf v1.5.2 // indirect go.uber.org/atomic v1.10.0 // indirect go.uber.org/multierr v1.8.0 // indirect + golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect + golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect + golang.org/x/text v0.3.3 // indirect + google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect ) diff --git a/go.sum b/go.sum index 0f22762..0a67bf4 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,36 @@ +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8= +github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= +github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ= github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -17,7 +43,64 @@ go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8= go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak= go.uber.org/zap v1.23.0 h1:OjGQ5KQDEUawVHxNwQgPpiypGHOxo2mNZsOqTak4fFY= go.uber.org/zap v1.23.0/go.mod h1:D+nX8jyLsMHMYrln8A0rJjFt/T/9/bGgIhAqxv5URuY= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= +golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= +golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= +google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= +google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 h1:+kGHl1aib/qcwaRi1CbqBZ1rk19r85MNUf8HaBghugY= +google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= +google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= +google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= +google.golang.org/grpc v1.49.0 h1:WTLtQzmQori5FUH25Pq4WT22oCsv8USpQ+F6rqtsmxw= +google.golang.org/grpc v1.49.0/go.mod h1:ZgQEeidpAuNRZ8iRrlBKXZQP1ghovWIVhdJRyCDK+GI= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= +google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= +google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= +honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/proto/servicea/.bazelignore b/proto/servicea/.bazelignore new file mode 100644 index 0000000..9b361cc --- /dev/null +++ b/proto/servicea/.bazelignore @@ -0,0 +1 @@ +servicea.pb.go diff --git a/proto/servicea/BUILD.bazel b/proto/servicea/BUILD.bazel new file mode 100644 index 0000000..f790672 --- /dev/null +++ b/proto/servicea/BUILD.bazel @@ -0,0 +1,30 @@ +load("@rules_proto//proto:defs.bzl", "proto_library") +load("@io_bazel_rules_go//go:def.bzl", "go_library") +load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library") + +proto_library( + name = "servicea_proto", + srcs = ["servicea.proto"], + visibility = ["//visibility:public"], +) + +go_proto_library( + name = "servicea_go_proto", + compilers = ["@io_bazel_rules_go//proto:go_grpc"], + importpath = "github.com/jankremlacek/go-bazel/proto/servicea", + proto = ":servicea_proto", + visibility = ["//visibility:public"], +) + +go_library( + name = "servicea", + embed = [":servicea_go_proto"], + importpath = "github.com/jankremlacek/go-bazel/proto/servicea", + visibility = ["//visibility:public"], +) + +alias( + name = "go_default_library", + actual = ":servicea", + visibility = ["//visibility:public"], +) diff --git a/proto/servicea/servicea.pb.go b/proto/servicea/servicea.pb.go new file mode 100755 index 0000000..d43fe13 --- /dev/null +++ b/proto/servicea/servicea.pb.go @@ -0,0 +1,301 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v3.14.0 +// source: proto/servicea/servicea.proto + +package servicea + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type SumRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + A int32 `protobuf:"varint,1,opt,name=a,proto3" json:"a,omitempty"` + B int32 `protobuf:"varint,2,opt,name=b,proto3" json:"b,omitempty"` +} + +func (x *SumRequest) Reset() { + *x = SumRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_servicea_servicea_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SumRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SumRequest) ProtoMessage() {} + +func (x *SumRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_servicea_servicea_proto_msgTypes[0] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SumRequest.ProtoReflect.Descriptor instead. +func (*SumRequest) Descriptor() ([]byte, []int) { + return file_proto_servicea_servicea_proto_rawDescGZIP(), []int{0} +} + +func (x *SumRequest) GetA() int32 { + if x != nil { + return x.A + } + return 0 +} + +func (x *SumRequest) GetB() int32 { + if x != nil { + return x.B + } + return 0 +} + +type SumResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Result int32 `protobuf:"varint,1,opt,name=result,proto3" json:"result,omitempty"` +} + +func (x *SumResponse) Reset() { + *x = SumResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_proto_servicea_servicea_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *SumResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SumResponse) ProtoMessage() {} + +func (x *SumResponse) ProtoReflect() protoreflect.Message { + mi := &file_proto_servicea_servicea_proto_msgTypes[1] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SumResponse.ProtoReflect.Descriptor instead. +func (*SumResponse) Descriptor() ([]byte, []int) { + return file_proto_servicea_servicea_proto_rawDescGZIP(), []int{1} +} + +func (x *SumResponse) GetResult() int32 { + if x != nil { + return x.Result + } + return 0 +} + +var File_proto_servicea_servicea_proto protoreflect.FileDescriptor + +var file_proto_servicea_servicea_proto_rawDesc = []byte{ + 0x0a, 0x1d, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x61, + 0x2f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x61, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, + 0x28, 0x0a, 0x0a, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0c, 0x0a, + 0x01, 0x61, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x61, 0x12, 0x0c, 0x0a, 0x01, 0x62, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x01, 0x62, 0x22, 0x25, 0x0a, 0x0b, 0x53, 0x75, 0x6d, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, + 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, + 0x32, 0x2c, 0x0a, 0x08, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x41, 0x12, 0x20, 0x0a, 0x03, + 0x53, 0x75, 0x6d, 0x12, 0x0b, 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x0c, 0x2e, 0x53, 0x75, 0x6d, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_proto_servicea_servicea_proto_rawDescOnce sync.Once + file_proto_servicea_servicea_proto_rawDescData = file_proto_servicea_servicea_proto_rawDesc +) + +func file_proto_servicea_servicea_proto_rawDescGZIP() []byte { + file_proto_servicea_servicea_proto_rawDescOnce.Do(func() { + file_proto_servicea_servicea_proto_rawDescData = protoimpl.X.CompressGZIP(file_proto_servicea_servicea_proto_rawDescData) + }) + return file_proto_servicea_servicea_proto_rawDescData +} + +var file_proto_servicea_servicea_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_proto_servicea_servicea_proto_goTypes = []interface{}{ + (*SumRequest)(nil), // 0: SumRequest + (*SumResponse)(nil), // 1: SumResponse +} +var file_proto_servicea_servicea_proto_depIdxs = []int32{ + 0, // 0: ServiceA.Sum:input_type -> SumRequest + 1, // 1: ServiceA.Sum:output_type -> SumResponse + 1, // [1:2] is the sub-list for method output_type + 0, // [0:1] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_proto_servicea_servicea_proto_init() } +func file_proto_servicea_servicea_proto_init() { + if File_proto_servicea_servicea_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_proto_servicea_servicea_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SumRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_proto_servicea_servicea_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*SumResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_proto_servicea_servicea_proto_rawDesc, + NumEnums: 0, + NumMessages: 2, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_proto_servicea_servicea_proto_goTypes, + DependencyIndexes: file_proto_servicea_servicea_proto_depIdxs, + MessageInfos: file_proto_servicea_servicea_proto_msgTypes, + }.Build() + File_proto_servicea_servicea_proto = out.File + file_proto_servicea_servicea_proto_rawDesc = nil + file_proto_servicea_servicea_proto_goTypes = nil + file_proto_servicea_servicea_proto_depIdxs = nil +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConnInterface + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion6 + +// ServiceAClient is the client API for ServiceA service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. +type ServiceAClient interface { + Sum(ctx context.Context, in *SumRequest, opts ...grpc.CallOption) (*SumResponse, error) +} + +type serviceAClient struct { + cc grpc.ClientConnInterface +} + +func NewServiceAClient(cc grpc.ClientConnInterface) ServiceAClient { + return &serviceAClient{cc} +} + +func (c *serviceAClient) Sum(ctx context.Context, in *SumRequest, opts ...grpc.CallOption) (*SumResponse, error) { + out := new(SumResponse) + err := c.cc.Invoke(ctx, "/ServiceA/Sum", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ServiceAServer is the server API for ServiceA service. +type ServiceAServer interface { + Sum(context.Context, *SumRequest) (*SumResponse, error) +} + +// UnimplementedServiceAServer can be embedded to have forward compatible implementations. +type UnimplementedServiceAServer struct { +} + +func (*UnimplementedServiceAServer) Sum(context.Context, *SumRequest) (*SumResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Sum not implemented") +} + +func RegisterServiceAServer(s *grpc.Server, srv ServiceAServer) { + s.RegisterService(&_ServiceA_serviceDesc, srv) +} + +func _ServiceA_Sum_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SumRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServiceAServer).Sum(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/ServiceA/Sum", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServiceAServer).Sum(ctx, req.(*SumRequest)) + } + return interceptor(ctx, in, info, handler) +} + +var _ServiceA_serviceDesc = grpc.ServiceDesc{ + ServiceName: "ServiceA", + HandlerType: (*ServiceAServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "Sum", + Handler: _ServiceA_Sum_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "proto/servicea/servicea.proto", +} diff --git a/proto/servicea/servicea.proto b/proto/servicea/servicea.proto new file mode 100644 index 0000000..e5cdb77 --- /dev/null +++ b/proto/servicea/servicea.proto @@ -0,0 +1,14 @@ +syntax = "proto3"; + +service ServiceA { + rpc Sum (SumRequest) returns (SumResponse); +} + +message SumRequest { + int32 a = 1; + int32 b = 2; +} + +message SumResponse { + int32 result = 1; +} diff --git a/services/a/BUILD.bazel b/services/a/BUILD.bazel deleted file mode 100644 index 3dbb481..0000000 --- a/services/a/BUILD.bazel +++ /dev/null @@ -1,19 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") - -go_library( - name = "a_lib", - srcs = ["main.go"], - importpath = "github.com/jankremlacek/go-bazel/services/a", - visibility = ["//visibility:private"], - deps = [ - "//shared", - "@org_uber_go_zap//:zap", - ], -) - -go_binary( - name = "a", - out = "service-a", - embed = [":a_lib"], - visibility = ["//visibility:public"], -) diff --git a/services/a/main.go b/services/a/main.go deleted file mode 100644 index 5443906..0000000 --- a/services/a/main.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "github.com/jankremlacek/go-bazel/shared" - "go.uber.org/zap" -) - -func main() { - logger, _ := zap.NewProduction() - defer logger.Sync() - - logger.Info("a says:", - zap.Int("sum", shared.Sum(1, 2)), - zap.String("version", shared.Version())) -} diff --git a/services/b/BUILD.bazel b/services/b/BUILD.bazel deleted file mode 100644 index caa32d2..0000000 --- a/services/b/BUILD.bazel +++ /dev/null @@ -1,19 +0,0 @@ -load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") - -go_library( - name = "b_lib", - srcs = ["main.go"], - importpath = "github.com/jankremlacek/go-bazel/services/b", - visibility = ["//visibility:private"], - deps = [ - "//shared", - "@org_uber_go_zap//:zap", - ], -) - -go_binary( - name = "b", - out = "service-b", - embed = [":b_lib"], - visibility = ["//visibility:public"], -) diff --git a/services/b/main.go b/services/b/main.go deleted file mode 100644 index 2fce795..0000000 --- a/services/b/main.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "github.com/jankremlacek/go-bazel/shared" - "go.uber.org/zap" -) - -func main() { - logger, _ := zap.NewProduction() - defer logger.Sync() - - logger.Info("b thinks:", - zap.Int("sum", shared.Sum(42, -21)), - zap.String("version", shared.Version())) -} diff --git a/services/servicea/BUILD.bazel b/services/servicea/BUILD.bazel new file mode 100644 index 0000000..b58c43d --- /dev/null +++ b/services/servicea/BUILD.bazel @@ -0,0 +1,24 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + +go_library( + name = "servicea_lib", + srcs = [ + "hander.go", + "main.go", + ], + importpath = "github.com/jankremlacek/go-bazel/services/servicea", + visibility = ["//visibility:private"], + deps = [ + "//proto/servicea", + "//shared", + "@org_golang_google_grpc//:go_default_library", + "@org_uber_go_zap//:zap", + ], +) + +go_binary( + name = "servicea", + out = "servicea", + embed = [":servicea_lib"], + visibility = ["//visibility:public"], +) diff --git a/services/servicea/hander.go b/services/servicea/hander.go new file mode 100644 index 0000000..5475819 --- /dev/null +++ b/services/servicea/hander.go @@ -0,0 +1,18 @@ +package main + +import ( + "context" + + pb "github.com/jankremlacek/go-bazel/proto/servicea" +) + +type Handler struct { + pb.UnimplementedServiceAServer +} + +func (h *Handler) Sum(_ context.Context, rqst *pb.SumRequest) (response *pb.SumResponse, err error) { + response = &pb.SumResponse{ + Result: rqst.GetA() + rqst.GetB(), + } + return +} diff --git a/services/servicea/main.go b/services/servicea/main.go new file mode 100644 index 0000000..94b2c6d --- /dev/null +++ b/services/servicea/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "net" + "os" + "os/signal" + "syscall" + + pb "github.com/jankremlacek/go-bazel/proto/servicea" + "github.com/jankremlacek/go-bazel/shared" + "go.uber.org/zap" + "google.golang.org/grpc" +) + +func main() { + var ( + err error + lis net.Listener + srv *grpc.Server + ) + + logger, _ := zap.NewProduction() + defer logger.Sync() + + if len(os.Args) != 2 { + logger.Fatal("Use: servicea [tcp-addr]") + } + if lis, err = net.Listen("tcp", os.Args[1]); err != nil { + logger.Fatal("Unable to bind gRPC", + zap.String("addr", os.Args[1]), + zap.Error(err)) + } + + srv = grpc.NewServer() + pb.RegisterServiceAServer(srv, new(Handler)) + + go func() { + if err := srv.Serve(lis); err != nil { + logger.Fatal("Error serving gRPC", zap.Error(err)) + } + }() + + logger.Info("Listening", + zap.String("at", os.Args[1]), + zap.String("version", shared.Version())) + + c := make(chan os.Signal, 1) + signal.Notify(c, os.Interrupt, syscall.SIGTERM) + <-c + + srv.GracefulStop() +} diff --git a/services/serviceb/BUILD.bazel b/services/serviceb/BUILD.bazel new file mode 100644 index 0000000..b00dcea --- /dev/null +++ b/services/serviceb/BUILD.bazel @@ -0,0 +1,21 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library") + +go_library( + name = "serviceb_lib", + srcs = ["main.go"], + importpath = "github.com/jankremlacek/go-bazel/services/serviceb", + visibility = ["//visibility:private"], + deps = [ + "//proto/servicea", + "@org_golang_google_grpc//:go_default_library", + "@org_golang_google_grpc//credentials/insecure", + "@org_uber_go_zap//:zap", + ], +) + +go_binary( + name = "serviceb", + out = "serviceb", + embed = [":serviceb_lib"], + visibility = ["//visibility:public"], +) diff --git a/services/serviceb/main.go b/services/serviceb/main.go new file mode 100644 index 0000000..bf1b6e5 --- /dev/null +++ b/services/serviceb/main.go @@ -0,0 +1,46 @@ +package main + +import ( + "context" + "os" + + pb "github.com/jankremlacek/go-bazel/proto/servicea" + "go.uber.org/zap" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" +) + +func main() { + var ( + conn *grpc.ClientConn + err error + response *pb.SumResponse + ) + + logger, _ := zap.NewProduction() + defer logger.Sync() + + if len(os.Args) != 2 { + logger.Fatal("Use: servicea [tcp-addr]") + } + + logger.Info("Contacting ServiceA", + zap.String("at", os.Args[1])) + + if conn, err = grpc.Dial(os.Args[1], grpc.WithTransportCredentials(insecure.NewCredentials())); err != nil { + logger.Fatal("Error dialing", + zap.String("to", os.Args[1]), + zap.Error(err)) + } + + if response, err = pb.NewServiceAClient(conn).Sum(context.TODO(), &pb.SumRequest{ + A: 42, + B: 21, + }); err != nil { + logger.Fatal("Unable to call RPC", + zap.Error(err)) + } + + logger.Info("Got response", + zap.Int("sum", int(response.Result))) +}