Add linter
diff --git a/.gitignore b/.gitignore
index 63ed09b..1e95a12 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,5 @@
priv/
bazel-*
gazelle*
+coverage.txt
diff --git a/core/kg/Makefile b/core/kg/Makefile
new file mode 100644
index 0000000..c962617
--- /dev/null
+++ b/core/kg/Makefile
@@ -0,0 +1,67 @@
+GO ?= $(shell command -v go 2> /dev/null)
+GO_TEST_FLAGS ?= -race
+
+export GO111MODULE=on
+
+MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
+MINIMUM_SUPPORTED_GO_MINOR_VERSION = 14
+GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
+GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
+GO_VERSION_VALIDATION_ERR_MSG = Golang version is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION)
+
+BUILDER_GOOS_GOARCH="$(shell $(GO) env GOOS)_$(shell $(GO) env GOARCH)"
+
+## Define the default target (make all)
+.PHONY: default
+default: all
+
+## Checks the code style, tests, runs the code.
+.PHONY: all
+all: check-style test run
+
+## Runs eslint and golangci-lint
+.PHONY: check-style
+check-style:
+ @if ! [ -x "$$(command -v golangci-lint)" ]; then \
+ echo "golangci-lint is not installed. Please see https://github.com/golangci/golangci-lint#install for installation instructions."; \
+ exit 1; \
+ fi; \
+
+ @echo Running golangci-lint
+ golangci-lint run ./...
+
+## Runs unit tests.
+.PHONY: test
+test:
+ @echo Running unit tests
+ $(GO) test -v $(GO_TEST_FLAGS) ./...
+
+## Creates a coverage report
+.PHONY: coverage
+coverage:
+ $(GO) test $(GO_TEST_FLAGS) -coverprofile=coverage.txt ./...
+ $(GO) tool cover -html=coverage.txt
+
+## Clean removes all artifacts.
+.PHONY: clean
+clean:
+ rm -fr coverage.txt
+ rm -fr server.log
+
+.PHONY: run
+run: validate-go-version
+ @echo Running Knowledge Graph services
+
+ $(GO) run ./cmd/
+
+.PHONY: validate-go-version
+validate-go-version: ## Validates the installed version of go against minimum requirement.
+ @if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
+ exit 0 ;\
+ elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
+ echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
+ exit 1; \
+ elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
+ echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
+ exit 1; \
+ fi
\ No newline at end of file
diff --git a/core/kg/model/user.go b/core/kg/model/user.go
index 156f4fa..dd34110 100644
--- a/core/kg/model/user.go
+++ b/core/kg/model/user.go
@@ -8,9 +8,8 @@
)
const (
- userNameMaxLength = 64
- userNameMinLength = 1
- userEmailMaxLength = 128
+ userNameMaxLength = 64
+ userNameMinLength = 1
)
// User contains the details about the user.
@@ -75,9 +74,6 @@
}
validUsernameChars := regexp.MustCompile(`^[a-z0-9\.\-_]+$`)
- if !validUsernameChars.MatchString(s) {
- return false
- }
- return true
+ return validUsernameChars.MatchString(s)
}
diff --git a/core/kg/server/servers_mock.go b/core/kg/server/servers_mock.go
index e2b6afc..2694329 100644
--- a/core/kg/server/servers_mock.go
+++ b/core/kg/server/servers_mock.go
@@ -30,8 +30,8 @@
Servers: []Server{grpcServer, httpServer},
Config: config,
}
- go grpcServer.Start()
- go httpServer.Start()
+ go grpcServer.Start() // nolint:errcheck
+ go httpServer.Start() // nolint:errcheck
time.Sleep(1 * time.Second)
return ts
}
@@ -40,7 +40,7 @@
done := make(chan bool)
go func() {
for _, server := range ts.Servers {
- server.Shutdown()
+ server.Shutdown() // nolint:errcheck
}
close(done)
}()