Skip to content

Commit 4609424

Browse files
authored
Merge pull request #4 from farooqazamwasimnl/feat/02-db-writer
feat: add db writer, types, logging, util and test infrastructure
2 parents 2808dbc + d1d270a commit 4609424

35 files changed

+2500
-447
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Set up Go
1818
uses: actions/setup-go@v5
1919
with:
20-
go-version: '1.23'
20+
go-version: '1.24'
2121

2222
- name: Install sqlc
2323
run: |

.golangci.yml

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Copyright IBM Corp. All Rights Reserved.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
version: "2"
6+
linters:
7+
enable:
8+
- containedctx
9+
- contextcheck
10+
- depguard
11+
- dupl
12+
- errname
13+
- errorlint
14+
- fatcontext
15+
- forcetypeassert
16+
- gocognit
17+
- goconst
18+
- gocritic
19+
- godot
20+
- gosec
21+
- intrange
22+
- ireturn
23+
- lll
24+
- maintidx
25+
- mirror
26+
- misspell
27+
- nilerr
28+
- nilnesserr
29+
- nolintlint
30+
- prealloc
31+
- revive
32+
- rowserrcheck
33+
- sqlclosecheck
34+
- testifylint
35+
- thelper
36+
- unconvert
37+
- unparam
38+
- wastedassign
39+
- whitespace
40+
- goheader
41+
settings:
42+
depguard:
43+
rules:
44+
main:
45+
deny:
46+
- pkg: github.com/pkg/errors
47+
desc: github.com/pkg/errors is no longer maintained
48+
errcheck:
49+
check-type-assertions: true
50+
errorlint:
51+
errorf: true
52+
asserts: false
53+
comparison: true
54+
fatcontext:
55+
check-struct-pointers: true
56+
gocognit:
57+
min-complexity: 15
58+
gosec:
59+
excludes:
60+
- G204
61+
- G404
62+
- G306
63+
govet:
64+
disable:
65+
- fieldalignment
66+
enable-all: true
67+
ireturn:
68+
allow:
69+
- error
70+
- empty
71+
- anon
72+
- stdlib
73+
- generic
74+
- (or|er)$
75+
- T
76+
- github.com/jackc/pgx/v5.Tx
77+
lll:
78+
line-length: 120
79+
maintidx:
80+
under: 20
81+
nolintlint:
82+
require-specific: true
83+
revive:
84+
enable-all-rules: true
85+
rules:
86+
- name: argument-limit
87+
arguments:
88+
- 4
89+
- name: line-length-limit
90+
arguments:
91+
- 120
92+
- name: file-header
93+
disabled: true
94+
- name: package-comments
95+
disabled: true
96+
- name: max-public-structs
97+
disabled: true
98+
- name: banned-characters
99+
disabled: true
100+
- name: cognitive-complexity
101+
disabled: true
102+
- name: cyclomatic
103+
disabled: true
104+
- name: function-length
105+
disabled: true
106+
- name: function-result-limit
107+
arguments:
108+
- 3
109+
- name: add-constant
110+
disabled: true
111+
- name: unhandled-error
112+
arguments:
113+
- fmt.Printf
114+
- fmt.Println
115+
- strings.Builder.WriteString
116+
- strings.Builder.WriteByte
117+
- strings.Builder.Write
118+
- name: confusing-naming
119+
disabled: true
120+
- name: var-naming
121+
disabled: true
122+
- name: comment-spacings
123+
arguments:
124+
- 'nolint:'
125+
rowserrcheck:
126+
packages:
127+
- github.com/jackc/pgx/v5
128+
goheader:
129+
template: |-
130+
Copyright IBM Corp. All Rights Reserved.
131+
132+
SPDX-License-Identifier: Apache-2.0
133+
exclusions:
134+
generated: lax
135+
warn-unused: true
136+
presets:
137+
- common-false-positives
138+
formatters:
139+
enable:
140+
- gofumpt
141+
- goimports
142+
settings:
143+
gofumpt:
144+
extra-rules: true
145+
goimports:
146+
local-prefixes:
147+
- github.com/LF-Decentralized-Trust-labs/fabric-x-block-explorer
148+
exclusions:
149+
generated: lax
150+
sort-order:
151+
- file
152+
- severity
153+
- linter

Makefile

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,51 @@
11
# Copyright IBM Corp. All Rights Reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
.PHONY: sqlc
4+
.PHONY: sqlc lint test test-no-db test-requires-db test-all coverage clean help
55

66
sqlc: ## Generate Go code from SQL using sqlc
77
@echo "Generating Go code from SQL files..."
88
sqlc generate
99
@echo "✅ SQLC code generation complete"
10+
11+
lint: ## Run golangci-lint
12+
@echo "Running linter..."
13+
golangci-lint run ./...
14+
@echo "✅ Lint passed"
15+
16+
test-no-db: ## Run tests that don't require database
17+
@echo "Running tests without database requirement..."
18+
go test -v -count=1 \
19+
./pkg/types/... \
20+
./pkg/util/...
21+
22+
test-requires-db: ## Run tests that require database (uses testcontainers by default)
23+
@echo "Running tests that require database..."
24+
go test -v -count=1 ./pkg/db/...
25+
26+
test-all: ## Run all tests
27+
@echo "Running all tests..."
28+
go test -v -count=1 ./pkg/...
29+
30+
test: test-all ## Alias for test-all
31+
32+
coverage: ## Generate test coverage report
33+
@echo "Generating coverage report..."
34+
@mkdir -p coverage
35+
go test -coverprofile=coverage/coverage.out ./pkg/...
36+
go tool cover -html=coverage/coverage.out -o coverage/coverage.html
37+
go tool cover -func=coverage/coverage.out
38+
@echo ""
39+
@echo "Coverage report generated: coverage/coverage.html"
40+
41+
clean: ## Remove build artifacts and coverage reports
42+
@echo "Cleaning build artifacts..."
43+
rm -rf coverage/
44+
@echo "Clean complete"
45+
46+
help: ## Display this help message
47+
@echo "Fabric X Block Explorer - Makefile targets"
48+
@echo ""
49+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}'
50+
51+
.DEFAULT_GOAL := help

go.mod

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,74 @@ module github.com/LF-Decentralized-Trust-labs/fabric-x-block-explorer
22

33
go 1.24.0
44

5-
require github.com/jackc/pgx/v5 v5.8.0
5+
require (
6+
github.com/hyperledger/fabric v2.1.1+incompatible
7+
github.com/jackc/pgx/v5 v5.8.0
8+
github.com/stretchr/testify v1.11.1
9+
github.com/testcontainers/testcontainers-go v0.40.0
10+
github.com/testcontainers/testcontainers-go/modules/postgres v0.40.0
11+
)
612

713
require (
14+
dario.cat/mergo v1.0.2 // indirect
15+
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
16+
github.com/Microsoft/go-winio v0.6.2 // indirect
17+
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
18+
github.com/cespare/xxhash/v2 v2.3.0 // indirect
19+
github.com/containerd/errdefs v1.0.0 // indirect
20+
github.com/containerd/errdefs/pkg v0.3.0 // indirect
21+
github.com/containerd/log v0.1.0 // indirect
22+
github.com/containerd/platforms v0.2.1 // indirect
23+
github.com/cpuguy83/dockercfg v0.3.2 // indirect
24+
github.com/davecgh/go-spew v1.1.1 // indirect
25+
github.com/distribution/reference v0.6.0 // indirect
26+
github.com/docker/docker v28.5.1+incompatible // indirect
27+
github.com/docker/go-connections v0.6.0 // indirect
28+
github.com/docker/go-units v0.5.0 // indirect
29+
github.com/ebitengine/purego v0.8.4 // indirect
30+
github.com/felixge/httpsnoop v1.0.4 // indirect
31+
github.com/go-logr/logr v1.4.3 // indirect
32+
github.com/go-logr/stdr v1.2.2 // indirect
33+
github.com/go-ole/go-ole v1.2.6 // indirect
34+
github.com/google/uuid v1.6.0 // indirect
35+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect
836
github.com/jackc/pgpassfile v1.0.0 // indirect
937
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
10-
golang.org/x/text v0.29.0 // indirect
38+
github.com/jackc/puddle/v2 v2.2.2 // indirect
39+
github.com/klauspost/compress v1.18.0 // indirect
40+
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
41+
github.com/magiconair/properties v1.8.10 // indirect
42+
github.com/moby/docker-image-spec v1.3.1 // indirect
43+
github.com/moby/go-archive v0.1.0 // indirect
44+
github.com/moby/patternmatcher v0.6.0 // indirect
45+
github.com/moby/sys/sequential v0.6.0 // indirect
46+
github.com/moby/sys/user v0.4.0 // indirect
47+
github.com/moby/sys/userns v0.1.0 // indirect
48+
github.com/moby/term v0.5.0 // indirect
49+
github.com/morikuni/aec v1.0.0 // indirect
50+
github.com/opencontainers/go-digest v1.0.0 // indirect
51+
github.com/opencontainers/image-spec v1.1.1 // indirect
52+
github.com/pkg/errors v0.9.1 // indirect
53+
github.com/pmezard/go-difflib v1.0.0 // indirect
54+
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
55+
github.com/shirou/gopsutil/v4 v4.25.6 // indirect
56+
github.com/sirupsen/logrus v1.9.3 // indirect
57+
github.com/sykesm/zap-logfmt v0.0.4 // indirect
58+
github.com/tklauser/go-sysconf v0.3.12 // indirect
59+
github.com/tklauser/numcpus v0.6.1 // indirect
60+
github.com/yusufpapurcu/wmi v1.2.4 // indirect
61+
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
62+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
63+
go.opentelemetry.io/otel v1.39.0 // indirect
64+
go.opentelemetry.io/otel/metric v1.39.0 // indirect
65+
go.opentelemetry.io/otel/trace v1.39.0 // indirect
66+
go.uber.org/multierr v1.11.0 // indirect
67+
go.uber.org/zap v1.27.1 // indirect
68+
golang.org/x/crypto v0.43.0 // indirect
69+
golang.org/x/sync v0.19.0 // indirect
70+
golang.org/x/sys v0.39.0 // indirect
71+
golang.org/x/text v0.34.0 // indirect
72+
google.golang.org/grpc v1.79.1 // indirect
73+
google.golang.org/protobuf v1.36.11 // indirect
74+
gopkg.in/yaml.v3 v3.0.1 // indirect
1175
)

0 commit comments

Comments
 (0)