Skip to content

Commit

Permalink
Fixed linter detected issues.
Browse files Browse the repository at this point in the history
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka committed Jun 18, 2020
1 parent 834b71e commit 0e0df36
Show file tree
Hide file tree
Showing 24 changed files with 1,468 additions and 335 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Types of changes:

### Fixed
- [172](https://github.com/grpc-ecosystem/go-grpc-middleware/pull/172) Passing ctx into retry and recover - [johanbrandhorst](https://github.com/johanbrandhorst)
- Numerious documentation fixes.
- Numerous documentation fixes.

## v1.0.0 - 2018-05-08
### Added
Expand Down
52 changes: 37 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,20 +1,45 @@
include .bingo/Variables.mk

SHELL=/bin/bash

PROVIDER_MODULES ?= $(shell ls -d $(PWD)/providers/*)
MODULES ?= $(PROVIDER_MODULES) $(PWD)/

GOBIN ?= $(firstword $(subst :, ,${GOPATH}))/bin

PROTOC_VERSION ?= 3.12.3
PROTOC ?= $(GOBIN)/protoc-$(PROTOC_VERSION)
TMP_GOPATH ?= /tmp/gopath


GO111MODULE ?= on
export GO111MODULE
GOPROXY ?= https://proxy.golang.org
export GOPROXY

define require_clean_work_tree
@git update-index -q --ignore-submodules --refresh

@if ! git diff-files --quiet --ignore-submodules --; then \
echo >&2 "cannot $1: you have unstaged changes."; \
git diff-files --name-status -r --ignore-submodules -- >&2; \
echo >&2 "Please commit or stash them."; \
exit 1; \
fi

@if ! git diff-index --cached --quiet HEAD --ignore-submodules --; then \
echo >&2 "cannot $1: your index contains uncommitted changes."; \
git diff-index --cached --name-status -r --ignore-submodules HEAD -- >&2; \
echo >&2 "Please commit or stash them."; \
exit 1; \
fi

endef

.PHONY: fmt
fmt:
@echo "Running fmt for all modules: ${MODULES}"
@$(GOIMPORTS) -local github.com/grpc-ecosystem/go-grpc-middleware/v2 -w ${MODULES}
fmt: $(GOIMPORTS)
@echo "Running fmt for all modules: $(MODULES)"
@$(GOIMPORTS) -local github.com/grpc-ecosystem/go-grpc-middleware/v2 -w $(MODULES)

.PHONY: proto
proto: ## Generates Go files from Thanos proto files.
Expand All @@ -23,27 +48,26 @@ proto: $(GOIMPORTS) $(PROTOC) $(PROTOC_GEN_GOGOFAST) ./grpctesting/testpb/test.p

.PHONY: test
test:
@echo "Running tests for all modules: ${MODULES}"
@$(foreach dir,$(PROVIDER_MODULES),$(MAKE) test_module DIR=$(dir))
@echo "Running tests for all modules: $(MODULES)"
for dir in $(MODULES) ; do \
$(MAKE) test_module DIR=$${dir} ; \
done
./scripts/test_all.sh

.PHONY: test_module
test_module:
@echo "Running tests for dir: $(DIR)"
cd $(DIR) && go test -v -race ./...

.PHONY: lint
lint: fmt
@echo "Running lint for all modules: ${MODULES}"
@$(foreach dir,$(MODULES),$(MAKE) lint_module DIR=$(dir))

.PHONY: lint_module
# PROTIP:
# Add
# --cpu-profile-path string Path to CPU profile output file
# --mem-profile-path string Path to memory profile output file
# to debug big allocations during linting.
lint: ## Runs various static analysis against our code.
lint_module: $(FAILLINT) $(GOLANGCI_LINT) $(MISSPELL)
lint: fmt $(FAILLINT) $(GOLANGCI_LINT) $(MISSPELL)
@echo "Running lint for all modules: $(MODULES)"
$(call require_clean_work_tree,"detected not clean master before running lint")
@echo ">> verifying modules being imported"
@$(FAILLINT) -paths "errors=github.com/pkg/errors,fmt.{Print,Printf,Println}" ./...
Expand All @@ -53,16 +77,14 @@ lint_module: $(FAILLINT) $(GOLANGCI_LINT) $(MISSPELL)
@$(GOLANGCI_LINT) run
@echo ">> detecting misspells"
@find . -type f | grep -v vendor/ | grep -vE '\./\..*' | xargs $(MISSPELL) -error
@echo ">> detecting white noise"
@find . -type f \( -name "*.md" -o -name "*.go" \) | SED_BIN="$(SED)" xargs scripts/cleanup-white-noise.sh
@echo ">> ensuring generated proto files are up to date"
@$(MAKE) proto
$(call require_clean_work_tree,"detected white noise or/and files without copyright; run 'make lint' file and commit changes.")
$(call require_clean_work_tree,"detected proto changes or other not formatted files; run 'make lint' file and commit changes.")

$(PROTOC):
@mkdir -p $(TMP_GOPATH)
@echo ">> fetching protoc@${PROTOC_VERSION}"
@PROTOC_VERSION="$(PROTOC_VERSION)" TMP_GOPATH="$(TMP_GOPATH)" scripts/installprotoc.sh
@echo ">> installing protoc@${PROTOC_VERSION}"
@mv -- "$(TMP_GOPATH)/bin/protoc" "$(GOBIN)/protoc-$(PROTOC_VERSION)"
@echo ">> produced $(GOBIN)/protoc-$(PROTOC_VERSION)"
@echo ">> produced $(GOBIN)/protoc-$(PROTOC_VERSION)"
5 changes: 3 additions & 2 deletions auth/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,13 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/v2/util/metautils"
)

var authedMarker struct{}

var (
commonAuthToken = "some_good_token"
overrideAuthToken = "override_token"

authedMarker = "some_context_marker"
goodPing = &testpb.PingRequest{Value: "something", SleepTimeMs: 9999}
goodPing = &testpb.PingRequest{Value: "something", SleepTimeMs: 9999}
)

// TODO(mwitkow): Add auth from metadata client dialer, which requires TLS.
Expand Down
4 changes: 3 additions & 1 deletion auth/examples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/grpc-ecosystem/go-grpc-middleware/v2/interceptors/tags"
)

var tokenInfoKey struct{}

func parseToken(token string) (struct{}, error) {
return struct{}{}, nil
}
Expand All @@ -36,7 +38,7 @@ func exampleAuthFunc(ctx context.Context) (context.Context, error) {
tags.Extract(ctx).Set("auth.sub", userClaimFromToken(tokenInfo))

// WARNING: in production define your own type to avoid context collisions
newCtx := context.WithValue(ctx, "tokenInfo", tokenInfo)
newCtx := context.WithValue(ctx, tokenInfoKey, tokenInfo)

return newCtx, nil
}
Expand Down
2 changes: 2 additions & 0 deletions chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"google.golang.org/grpc"
)

// TODO(bwplotka): Remove and replace with updated gRPC default chaining WithChainUnaryInterceptor etc.

// ChainUnaryServer creates a single interceptor out of a chain of many interceptors.
//
// Execution is done in left-to-right order, including passing of context.
Expand Down
172 changes: 0 additions & 172 deletions chain_test.go

This file was deleted.

Loading

0 comments on commit 0e0df36

Please sign in to comment.