Skip to content

Commit

Permalink
Refactor library structure (#11)
Browse files Browse the repository at this point in the history
* Change package structure

* Add tests for config provider

* Update copyrights

* Correct struct name. Remove redundand code

* Correct makefile

* Add tests for routers

* Correct link to license in copyright

* Review correction. Make connection manager internal

* Correct prometheus module registration

* Add raw listener subscription

* Refactor subscribing for messages

* Extract common part for subscription handling

* Extract start and subscribe methods

* Migrate event router to common subscriber implementation

* Added trace level for logging (#12)

* Cleanup subscribers code

* Store generate protobuf structs in repository

* Update testcontainers dep

* Execute go mod tidy

---------

Co-authored-by: Nikita Smirnov <[email protected]>
  • Loading branch information
OptimumCode and Nikita-Smirnov-Exactpro authored Sep 14, 2023
1 parent 7b272c7 commit 6b5f3cb
Show file tree
Hide file tree
Showing 93 changed files with 8,327 additions and 2,346 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ jobs:
- name: Install protoc
run: sudo apt-get update && sudo apt-get install -y protobuf-compiler && protoc --version

- name: Init repository
run: make prepare-main-module
- name: Check gRPC generated files not manually changed
shell: bash
run: |
make prepare-grpc-module
CHANGED=$(git diff --name-only ./pkg/common/grpc/**/*.go | wc -l)
if [ "${CHANGED}" -ne "0" ]; then
git diff ./pkg/common/grpc/**/*.go
echo "Committed Protobuf files do not match the newly generated. Please, regenerate Protobuf and commit changes"
exit 1
fi
- name: Build sources
run: make build
- name: Check sources
run: make test
run: make run-test
16 changes: 0 additions & 16 deletions Dockerfile

This file was deleted.

45 changes: 17 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,43 @@ SRC_MAIN_PROTO_DIR=src/main/proto
GITHUB_TH2=github.com/th2-net

TH2_GRPC_COMMON=th2-grpc-common
TH2_GRPC_COMMON_URL=$(GITHUB_TH2)/$(TH2_GRPC_COMMON)@makefile
TH2_GRPC_COMMON_URL=$(GITHUB_TH2)/$(TH2_GRPC_COMMON)@4.3.0-dev

MODULE_NAME=th2-grpc
MODULE_DIR=$(MODULE_NAME)

PROTOBUF_VERSION=v1.5.2
MODULE_DIR=pkg/common/grpc

PROTOC_VERSION=21.12

default: prepare-main-module build
init-work-space: clean-grpc-module prepare-grpc-module configure-grpc-generator generate-grpc-files tidy

configure-go:
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
configure-grpc-generator:
go install google.golang.org/protobuf/cmd/[email protected]

clean-grpc-module:
-rm -rf $(MODULE_DIR)

prepare-grpc-module: clean-grpc-module
mkdir $(MODULE_DIR)
cd $(MODULE_DIR) && go mod init $(MODULE_NAME)
prepare-grpc-module:
- mkdir $(MODULE_DIR)
cd $(MODULE_DIR)

cd $(MODULE_DIR) \
&& go get -u -t $(TH2_GRPC_COMMON_URL) \
&& go get -u -t github.com/golang/protobuf@$(PROTOBUF_VERSION) \
&& go get -u -t google.golang.org/[email protected] \
&& go get -u -t github.com/google/[email protected]

- go work init
go work use ./$(MODULE_DIR)
&& go get $(TH2_GRPC_COMMON_URL) \
&& go get google.golang.org/[email protected] \
&& go get github.com/google/[email protected]

genrate-grpc-files: prepare-grpc-module configure-go
generate-grpc-files:
$(eval $@_PROTO_DIR := $(shell go list -m -f '{{.Dir}}' $(TH2_GRPC_COMMON_URL))/$(SRC_MAIN_PROTO_DIR))
protoc \
--go_out=$(MODULE_DIR) \
--go_opt=paths=source_relative \
--go-grpc_out=$(MODULE_DIR) \
--go-grpc_opt=paths=source_relative \
--proto_path=$($@_PROTO_DIR) \
$(shell find $($@_PROTO_DIR) -name '*.proto' )

prepare-main-module: genrate-grpc-files
- go work init
go work use .
tidy:
go mod tidy -v

build:
go vet ./...
go build -v -race ./...
go build -v ./...

test:
go test -v ./...
run-test:
go test -v -race ./...
14 changes: 0 additions & 14 deletions build.sh

This file was deleted.

46 changes: 39 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,54 @@ require (
github.com/prometheus/client_golang v1.14.0
github.com/rs/zerolog v1.29.0
github.com/streadway/amqp v1.0.0
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.1
github.com/stretchr/testify v1.8.4
github.com/testcontainers/testcontainers-go v0.23.0
google.golang.org/grpc v1.58.0
google.golang.org/protobuf v1.31.0
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/containerd/containerd v1.7.6 // indirect
github.com/cpuguy83/dockercfg v0.3.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.6+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.1 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/moby/patternmatcher v0.6.0 // indirect
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc4 // indirect
github.com/opencontainers/runc v1.1.9 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.15.0 // indirect
golang.org/x/sys v0.12.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/tools v0.13.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230913181813-007df8e322eb // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 6b5f3cb

Please sign in to comment.