Skip to content

Commit 0ed85e4

Browse files
authored
Add golanglint-ci for static checking (#13)
* Add golanglint-ci for static checking * update delete-artifact action to latest version
1 parent 091a964 commit 0ed85e4

File tree

13 files changed

+70
-54
lines changed

13 files changed

+70
-54
lines changed

.github/workflows/PR.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ on:
1111
jobs:
1212
vet:
1313
uses: ./.github/workflows/vet.yml
14-
check-generated-code:
15-
uses: ./.github/workflows/check-generated-code.yml
1614
unit-test:
1715
uses: ./.github/workflows/unit.yml
16+
lint:
17+
uses: ./.github/workflows/lint.yml
1818
build:
1919
if: ${{ always() && contains(join(needs.*.result, ','), 'success') }} # if all `needs` jobs are successful
20-
needs: [vet, check-generated-code, unit-test]
20+
needs: [vet, unit-test, lint]
2121
secrets: inherit
2222
uses: ./.github/workflows/build.yml
2323
cleanup:

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
env-file: .github/development.env
1919

2020
- name: Setup Go ${{ env.GO_VERSION }}
21-
uses: actions/setup-go@v4
21+
uses: actions/setup-go@v5
2222
with:
2323
go-version: ${{ env.GO_VERSION }}
2424

@@ -31,7 +31,7 @@ jobs:
3131
run: docker save ${{ env.REGISTRY }}/${{ env.ORG }}/${{ env.IMAGE }}:dev -o /tmp/${{ env.IMAGE }}.tar
3232

3333
- name: Upload image artifact
34-
uses: actions/upload-artifact@v3
34+
uses: actions/upload-artifact@v4
3535
with:
3636
name: ${{ env.IMAGE }}
3737
retention-days: 1

.github/workflows/check-generated-code.yml

Lines changed: 0 additions & 33 deletions
This file was deleted.

.github/workflows/cleanup.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
env-file: .github/development.env
1919

2020
- name: Delete artifacts
21-
uses: geekyeggo/delete-artifact@v4
21+
uses: geekyeggo/delete-artifact@v5
2222
with:
2323
name: ${{ env.IMAGE }}
24-
token: ${{ secrets.PAT_CI_BOUNDLESS }}

.github/workflows/lint.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: golangci-lint
2+
3+
on:
4+
workflow_call:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
golangci:
11+
name: lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: actions/setup-go@v5
16+
with:
17+
go-version: ${{ env.GO_VERSION }}
18+
- name: golangci-lint
19+
uses: golangci/golangci-lint-action@v6
20+
with:
21+
version: v1.61.0

.github/workflows/unit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
env-file: .github/development.env
1919

2020
- name: Setup Go ${{ env.GO_VERSION }}
21-
uses: actions/setup-go@v4
21+
uses: actions/setup-go@v5
2222
with:
2323
go-version: ${{ env.GO_VERSION }}
2424

.github/workflows/vet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
env-file: .github/development.env
1919

2020
- name: Setup Go ${{ env.GO_VERSION }}
21-
uses: actions/setup-go@v4
21+
uses: actions/setup-go@v5
2222
with:
2323
go-version: ${{ env.GO_VERSION }}
2424

.golangci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
linters:
2+
# Disable all linters.
3+
# Default: false
4+
disable-all: true
5+
# Enable specific linter
6+
# https://golangci-lint.run/usage/linters/#enabled-by-default
7+
enable:
8+
- bodyclose
9+
- errcheck
10+
- gosimple
11+
- govet
12+
- ineffassign
13+
- staticcheck
14+
- unused

Makefile

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
MAIN:=cmd/main.go
22

33
# LDFLAGS
4-
VERSION:=
5-
#VERSION := $(shell git tag --sort=committerdate | tail -1)
6-
COMMIT := $(shell git rev-parse HEAD)
7-
DATE := $(shell date -u '+%Y-%m-%d')
4+
VERSION ?= dev
5+
COMMIT ?= $(shell git rev-parse HEAD)
6+
DATE ?= $(shell date -u '+%Y-%m-%d')
87

98
LDFLAGS := "-X 'main.version=${VERSION}' \
109
-X 'main.commit=${COMMIT}' \
@@ -18,7 +17,7 @@ help: ## Display this help.
1817
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
1918

2019
.PHONY: all
21-
all: fmt vet build ## Do all the things
20+
all: fmt vet lint build ## Do all the things
2221

2322
.PHONY: print-%
2423
print-%:
@@ -28,7 +27,7 @@ print-%:
2827

2928
.PHONY: buf
3029
buf: ## Run buf lint and breaking change checks
31-
@buf generate
30+
@go run github.com/bufbuild/buf/cmd/[email protected] generate
3231

3332
.PHONY: build
3433
build: ## Build the binary
@@ -80,12 +79,18 @@ fmt: ## Run go fmt against code.
8079
vet: ## Run go vet against code.
8180
@go vet ${MAIN}
8281

82+
.PHONY: lint
83+
lint: ## Run golangci-lint against code.
84+
@go run github.com/golangci/golangci-lint/cmd/[email protected] run
85+
8386
##@ Dependencies
8487
.PHONY: download
8588
download:
8689
@echo "Download go.mod dependencies"
8790
@go mod download
8891

92+
93+
8994
.PHONY: install-tools
9095
install-tools: download
9196
@echo "Install tools from tools/tools.go"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ make install-tools
5656
**buf cli**
5757

5858
```bash
59-
curl https://github.com/bufbuild/buf/releases/download/v1.35.1/buf-Linux-x86_64 -o buf
59+
curl https://github.com/bufbuild/buf/releases/download/v1.43.0/buf-Linux-x86_64 -o buf
6060
chmod +x buf
6161
sudo mv buf /usr/local/bin
6262
```

internal/middlewares/authn.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ const (
1616
dexKeysURL = "http://authentication-dex:5556/dex/keys"
1717

1818
dexClientName = "mke-dashboard"
19-
20-
// userInfoCtxKey is the key used to store the user information in the request context.
21-
userInfoCtxKey = "userInfoKey"
2219
)
2320

21+
// userInfoCtxKey is the key used to store the user information in the request context.
22+
23+
type userInfoKey struct{}
24+
2425
// user contains the user information extracted from the ID token claims.
2526
type user struct {
2627
email string
@@ -57,7 +58,7 @@ func authenticationMiddleware() runtime.Middleware {
5758
log.Debug().Msg("Authenticated user: " + u.email)
5859

5960
// Attach user information to the request context for next middlewares to use
60-
ctx := context.WithValue(r.Context(), userInfoCtxKey, u)
61+
ctx := context.WithValue(r.Context(), userInfoKey{}, u)
6162

6263
next(w, r.WithContext(ctx), pathParams)
6364
}

internal/middlewares/authz.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func authorizationMiddleware() runtime.Middleware {
4141
log.Debug().Msg("Authorizing request")
4242

4343
// get user info from the context
44-
u := r.Context().Value(userInfoCtxKey)
44+
u := r.Context().Value(userInfoKey{})
4545
if u == nil {
4646
log.Error().Err(fmt.Errorf("failed to get user info from context"))
4747
http.Error(w, "Internal Server Error", http.StatusInternalServerError)

internal/tls/tls.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,17 @@ const (
2121
func LoadTLSConfig(certDir string) (*tls.Config, error) {
2222
log.Info().Msgf("Loading TLS configuration from %s", certDir)
2323
ca, err := readFile(path.Join(certDir, caCertFile))
24+
if err != nil {
25+
return nil, fmt.Errorf("unable to read CA crt from file %s: %w", path.Join(certDir, caCertFile), err)
26+
}
2427
cert, err := readFile(path.Join(certDir, certFile))
28+
if err != nil {
29+
return nil, fmt.Errorf("unable to read client crt from file %s: %w", path.Join(certDir, certFile), err)
30+
}
2531
key, err := readFile(path.Join(certDir, keyFile))
32+
if err != nil {
33+
return nil, fmt.Errorf("unable to read client key from file %s: %w", path.Join(certDir, keyFile), err)
34+
}
2635

2736
cPool := x509.NewCertPool()
2837
if !cPool.AppendCertsFromPEM(ca) {

0 commit comments

Comments
 (0)