Compare commits

...

3 commits

Author SHA1 Message Date
3893ca67ac
[#124] rpc/client: Allow to pass custom grpc.CallOption options
All checks were successful
Tests and linters / Lint (pull_request) Successful in 46s
DCO action / DCO (pull_request) Successful in 1m4s
Tests and linters / Tests (pull_request) Successful in 1m6s
Tests and linters / Tests with -race (pull_request) Successful in 1m7s
Those options are used when creating a new grc.ClientStream.

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
2024-10-16 18:01:18 +03:00
88789d5f4a
[#124] Makefile: Add pre-commit related targets
Add the following targets:
- `pre-commit` to install pre-commit hooks
- `unpre-commit` to uninstall pre-commit hooks
- `pre-commit-run` to run pre-commit hooks

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
2024-10-16 18:01:11 +03:00
af7db13d51
[#124] Makefile: Add lint-install target
Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
2024-10-16 18:01:02 +03:00
4 changed files with 56 additions and 6 deletions

View file

@ -36,7 +36,10 @@ repos:
types: [go] types: [go]
language: system language: system
- repo: https://github.com/golangci/golangci-lint - repo: local
rev: v1.60.3
hooks: hooks:
- id: golangci-lint - id: make-lint
name: Run Make Lint
entry: make lint
language: system
pass_filenames: false

View file

@ -8,13 +8,18 @@ PROTOC_OS_VERSION=osx-x86_64
ifeq ($(shell uname), Linux) ifeq ($(shell uname), Linux)
PROTOC_OS_VERSION=linux-x86_64 PROTOC_OS_VERSION=linux-x86_64
endif endif
LINT_VERSION ?= 1.60.3
TRUECLOUDLAB_LINT_VERSION ?= 0.0.7
BIN = bin BIN = bin
PROTOBUF_DIR ?= $(abspath $(BIN))/protobuf PROTOBUF_DIR ?= $(abspath $(BIN))/protobuf
PROTOC_DIR ?= $(PROTOBUF_DIR)/protoc-v$(PROTOC_VERSION) PROTOC_DIR ?= $(PROTOBUF_DIR)/protoc-v$(PROTOC_VERSION)
PROTOC_GEN_GO_DIR ?= $(PROTOBUF_DIR)/protoc-gen-go-$(PROTOC_GEN_GO_VERSION) PROTOC_GEN_GO_DIR ?= $(PROTOBUF_DIR)/protoc-gen-go-$(PROTOC_GEN_GO_VERSION)
OUTPUT_LINT_DIR ?= $(abspath $(BIN))/linters
LINT_DIR = $(OUTPUT_LINT_DIR)/golangci-lint-$(LINT_VERSION)-v$(TRUECLOUDLAB_LINT_VERSION)
TMP_DIR := .cache
.PHONY: dep fmts fumpt imports protoc test lint version help $(BIN)/protogen protoc-test .PHONY: dep fmts fumpt imports protoc test version help $(BIN)/protogen protoc-test
# Pull go dependencies # Pull go dependencies
dep: dep:
@ -92,9 +97,43 @@ test:
@echo "⇒ Running go test" @echo "⇒ Running go test"
@GOFLAGS="$(GOFLAGS)" go test ./... @GOFLAGS="$(GOFLAGS)" go test ./...
.PHONY: lint-install lint
# Install linters
lint-install:
@rm -rf $(OUTPUT_LINT_DIR)
@mkdir $(OUTPUT_LINT_DIR)
@mkdir -p $(TMP_DIR)
@rm -rf $(TMP_DIR)/linters
@git -c advice.detachedHead=false clone --branch v$(TRUECLOUDLAB_LINT_VERSION) https://git.frostfs.info/TrueCloudLab/linters.git $(TMP_DIR)/linters
@@make -C $(TMP_DIR)/linters lib CGO_ENABLED=1 OUT_DIR=$(OUTPUT_LINT_DIR)
@rm -rf $(TMP_DIR)/linters
@rmdir $(TMP_DIR) 2>/dev/null || true
@CGO_ENABLED=1 GOBIN=$(LINT_DIR) go install -trimpath github.com/golangci/golangci-lint/cmd/golangci-lint@v$(LINT_VERSION)
# Run linters # Run linters
lint: lint:
@golangci-lint run @if [ ! -d "$(LINT_DIR)" ]; then \
make lint-install; \
fi
$(LINT_DIR)/golangci-lint run
.PHONY: pre-commit unpre-commit pre-commit-run
# Activate pre-commit hooks
pre-commit:
pre-commit install --hook-type pre-commit
# Deactivate pre-commit hooks
unpre-commit:
pre-commit uninstall --hook-type pre-commit
# Run pre-commit hooks
pre-commit-run:
@pre-commit run --all-files --hook-stage manual
# Print version # Print version
version: version:

View file

@ -55,7 +55,7 @@ func (c *Client) Init(info common.CallMethodInfo, opts ...CallOption) (MessageRe
StreamName: info.Name, StreamName: info.Name,
ServerStreams: info.ServerStream(), ServerStreams: info.ServerStream(),
ClientStreams: info.ClientStream(), ClientStreams: info.ClientStream(),
}, toMethodName(info)) }, toMethodName(info), c.grpcCallOpts...)
if err != nil { if err != nil {
cancel() cancel()
return nil, err return nil, err

View file

@ -24,6 +24,7 @@ type cfg struct {
tlsCfg *tls.Config tlsCfg *tls.Config
grpcDialOpts []grpc.DialOption grpcDialOpts []grpc.DialOption
grpcCallOpts []grpc.CallOption
conn Conn conn Conn
} }
@ -127,3 +128,10 @@ func WithGRPCDialOptions(opts []grpc.DialOption) Option {
c.grpcDialOpts = append(c.grpcDialOpts, opts...) c.grpcDialOpts = append(c.grpcDialOpts, opts...)
} }
} }
// WithGRPCDialOptions returns an option to specify grpc.Call.
func WithGRPCCallOptions(opts []grpc.CallOption) Option {
return func(c *cfg) {
c.grpcCallOpts = append(c.grpcCallOpts, opts...)
}
}