Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
- name: Verify dependencies
run: |
go mod verify
cd test && go mod verify

- name: Run tests
run: make test-coverage
Expand Down Expand Up @@ -87,9 +86,6 @@ jobs:
- name: Build
run: go build -v ./...

- name: Build test package
run: cd test && go build -v ./...

security:
name: Security Scan
runs-on: ubuntu-latest
Expand Down
91 changes: 36 additions & 55 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,76 +1,54 @@
TEST_DIR := ./test
COVER_PKG := ./...

.PHONY: help \
lint \
test \
test-verbose \
test-coverage \
test-coverage-html \
test-clean \
mock \
install-pre-push-hook \
uninstall-pre-push-hook
.PHONY: help lint build test test-verbose test-coverage test-coverage-html test-clean install-pre-push-hook uninstall-pre-push-hook mock

help:
@echo "Makefile commands:"
@echo " make lint - Run golangci-lint on the codebase"
@echo " make test - Run all tests"
@echo " make test-verbose - Run all tests with verbose output"
@echo " make test-coverage - Run all tests with coverage report"
@echo " make test-coverage-html - Run all tests and generate HTML coverage report"
@echo " make test-clean - Clean test cache and run tests"
@echo " make mock - Generate mock implementations"
@echo " make install-pre-push-hook - Install the pre-push git hook"
@echo " make uninstall-pre-push-hook - Uninstall the pre-push git hook"
@echo "Available commands:"
@echo " help - Show this help message"
@echo " lint - Run golangci-lint on the codebase"
@echo " build - Build the project"
@echo " test - Run all tests"
@echo " test-verbose - Run all tests with verbose output"
@echo " test-coverage - Run tests with coverage report for each package"
@echo " test-coverage-html - Run tests and generate HTML coverage reports for each package"
@echo " test-clean - Clean test cache and run tests"
@echo " install-pre-push-hook - Install the pre-push git hook"
@echo " uninstall-pre-push-hook - Uninstall the pre-push git hook"
@echo " mock - Generate mocks"

lint:
golangci-lint run ./...

build:
go build -v ./...

test:
@echo "Running all tests..."
@if [ -d $(TEST_DIR) ]; then \
go test $(TEST_DIR)/...; \
else \
echo "No tests found in $(TEST_DIR), skipping."; \
fi
go test ./...

test-verbose:
@echo "Running all tests with verbose output..."
@if [ -d $(TEST_DIR) ]; then \
go test -v $(TEST_DIR)/...; \
else \
echo "No tests found in $(TEST_DIR), skipping."; \
fi
go test -v ./...

test-coverage:
@echo "Running all tests with coverage report..."
@if [ -d $(TEST_DIR) ]; then \
go test -v -cover -coverprofile=coverage.out -coverpkg=$(COVER_PKG) $(TEST_DIR)/...; \
else \
echo "No tests found in $(TEST_DIR), skipping."; \
fi
@echo "Running tests with coverage report for each package..."
@for pkg in $$(go list ./...); do \
pkgname=$$(echo $$pkg | tr '/' '-'); \
echo "Coverage for $$pkg:"; \
go test -v -coverpkg=$$pkg -coverprofile=coverage-$$pkgname.out $$pkg; \
done

test-coverage-html:
@echo "Running all tests and generating HTML coverage report..."
@if [ -d $(TEST_DIR) ]; then \
go test -v -cover -coverprofile=coverage.out -coverpkg=$(COVER_PKG) $(TEST_DIR)/... && \
go tool cover -html=coverage.out -o coverage.html && \
echo "Coverage report generated: coverage.html"; \
else \
echo "No tests found in $(TEST_DIR), skipping."; \
fi
@echo "Running tests and generating HTML coverage reports for each package..."
@for pkg in $$(go list ./...); do \
pkgname=$$(echo $$pkg | tr '/' '-'); \
echo "Coverage for $$pkg:"; \
go test -v -coverpkg=$$pkg -coverprofile=coverage-$$pkgname.out $$pkg; \
go tool cover -html=coverage-$$pkgname.out -o coverage-$$pkgname.html; \
done
@echo "Coverage reports generated: coverage-*.html"

test-clean:
@echo "Cleaning test cache and running tests..."
@if [ -d $(TEST_DIR) ]; then \
go clean -testcache && go test -v $(TEST_DIR)/...; \
else \
echo "No tests found in $(TEST_DIR), skipping."; \
fi

mock:
@scripts/gen-mocks.sh
go clean -testcache && go test -v ./...

install-pre-push-hook:
@echo "Installing pre-push git hook..."
Expand All @@ -83,3 +61,6 @@ uninstall-pre-push-hook:
@echo "Uninstalling pre-push git hook..."
@rm -f .git/hooks/pre-push
@echo "Pre-push hook uninstalled successfully!"

mock:
@scripts/gen-mocks.sh
8 changes: 1 addition & 7 deletions base_entity.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,17 @@
package crud

import (
"database/sql"
"time"

"github.com/google/uuid"
)

type BaseEntity struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()"`
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:uuidv7()"`
Comment thread
itsLeonB marked this conversation as resolved.
CreatedAt time.Time
UpdatedAt time.Time `gorm:"autoUpdateTime"`
DeletedAt sql.NullTime
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

func (be BaseEntity) IsZero() bool {
return be.ID == uuid.Nil
}

func (be BaseEntity) IsDeleted() bool {
return be.DeletedAt.Valid
}
17 changes: 12 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ go 1.25.0

require (
github.com/google/uuid v1.6.0
github.com/itsLeonB/ezutil/v2 v2.0.0
github.com/rotisserie/eris v0.5.4
github.com/stretchr/testify v1.11.0
github.com/itsLeonB/ezutil/v2 v2.2.1
github.com/itsLeonB/ungerr v0.2.0
github.com/stretchr/testify v1.11.1
go.uber.org/mock v0.6.0
gorm.io/driver/sqlite v1.6.0
gorm.io/gorm v1.30.1
Expand All @@ -18,9 +18,16 @@ require (
github.com/jinzhu/now v1.1.5 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/mattn/go-sqlite3 v1.14.22 // indirect
github.com/mfridman/interpolate v0.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
golang.org/x/text v0.24.0 // indirect
github.com/pressly/goose/v3 v3.26.0 // indirect
github.com/sethvargo/go-retry v0.3.0 // indirect
github.com/shopspring/decimal v1.4.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/sync v0.16.0 // indirect
golang.org/x/text v0.27.0 // indirect
google.golang.org/genproto v0.0.0-20250826171959-ef028d996bc1 // indirect
google.golang.org/protobuf v1.36.8 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
56 changes: 48 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/itsLeonB/ezutil/v2 v2.0.0 h1:4o6nVMzCIr56ggXifDG7Mr+ucDDUg3bVeuiNjsFVcRI=
github.com/itsLeonB/ezutil/v2 v2.0.0/go.mod h1:fiUusldH3h+Y3vYimdloT+CBVO2AKT0xEtXvSHgvTts=
github.com/itsLeonB/ezutil/v2 v2.2.1 h1:hXjLOTrZoD1BYkd/jYErx+cSwrwrW7ay6TX0UozMD98=
github.com/itsLeonB/ezutil/v2 v2.2.1/go.mod h1:b1L2eUJtM5z5Kf+zXVPoVtSpjCBLt4CUDVhGQWz0bsI=
github.com/itsLeonB/ungerr v0.2.0 h1:+IMzMcgWuywsnASGzzWamqHdgNxZPYMOg4SoZ61XA0I=
github.com/itsLeonB/ungerr v0.2.0/go.mod h1:CGA9XktVW4iE5afcM/qZxHG/iVUUEPg3hklBvZnfrGg=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
Expand All @@ -17,21 +23,47 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY=
github.com/mfridman/interpolate v0.0.2/go.mod h1:p+7uk6oE07mpE/Ik1b8EckO0O4ZXiGAfshKBWLUM9Xg=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pressly/goose/v3 v3.26.0 h1:KJakav68jdH0WDvoAcj8+n61WqOIaPGgH0bJWS6jpmM=
github.com/pressly/goose/v3 v3.26.0/go.mod h1:4hC1KrritdCxtuFsqgs1R4AU5bWtTAf+cnWvfhf2DNY=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/rotisserie/eris v0.5.4 h1:Il6IvLdAapsMhvuOahHWiBnl1G++Q0/L5UIkI5mARSk=
github.com/rotisserie/eris v0.5.4/go.mod h1:Z/kgYTJiJtocxCbFfvRmO+QejApzG6zpyky9G1A4g9s=
github.com/stretchr/testify v1.11.0 h1:ib4sjIrwZKxE5u/Japgo/7SJV3PvgjGiRNAvTVGqQl8=
github.com/stretchr/testify v1.11.0/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE=
github.com/sethvargo/go-retry v0.3.0/go.mod h1:mNX17F0C/HguQMyMyJxcnU471gOZGxCLyYaFyAZraas=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.uber.org/mock v0.6.0 h1:hyF9dfmbgIX5EfOdasqLsWD6xqpNZlXblLB/Dbnwv3Y=
go.uber.org/mock v0.6.0/go.mod h1:KiVJ4BqZJaMj4svdfmHM0AUx4NJYO8ZNpPnZn1Z+BBU=
golang.org/x/text v0.24.0 h1:dd5Bzh4yt5KYA8f9CJHCP4FB4D51c2c6JvN37xJJkJ0=
golang.org/x/text v0.24.0/go.mod h1:L8rBsPeo2pSS+xqN0d5u2ikmjtmoJbDBT1b7nHvFCdU=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b h1:M2rDM6z3Fhozi9O7NWsxAkg/yqS/lQJ6PmkyIV3YP+o=
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto v0.0.0-20250826171959-ef028d996bc1 h1:Nm5SEGIguOIBDXs5rhfz2aKwEVWlgwC58UcmEnLDc8Y=
google.golang.org/genproto v0.0.0-20250826171959-ef028d996bc1/go.mod h1:Jz9LrroM7Mcm+a0QrLh4UpZ1B/WhjIbqwEcUf4y08nQ=
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
Expand All @@ -43,3 +75,11 @@ gorm.io/driver/sqlite v1.6.0 h1:WHRRrIiulaPiPFmDcod6prc4l2VGVWHz80KspNsxSfQ=
gorm.io/driver/sqlite v1.6.0/go.mod h1:AO9V1qIQddBESngQUKWL9yoH93HIeA1X6V633rBwyT8=
gorm.io/gorm v1.30.1 h1:lSHg33jJTBxs2mgJRfRZeLDG+WZaHYCk3Wtfl6Ngzo4=
gorm.io/gorm v1.30.1/go.mod h1:8Z33v652h4//uMA76KjeDH8mJXPm1QNCYrMeatR0DOE=
modernc.org/libc v1.66.3 h1:cfCbjTUcdsKyyZZfEUKfoHcP3S0Wkvz3jgSzByEWVCQ=
modernc.org/libc v1.66.3/go.mod h1:XD9zO8kt59cANKvHPXpx7yS2ELPheAey0vjIuZOhOU8=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/sqlite v1.38.2 h1:Aclu7+tgjgcQVShZqim41Bbw9Cho0y/7WzYptXqkEek=
modernc.org/sqlite v1.38.2/go.mod h1:cPTJYSlgg3Sfg046yBShXENNtPrWrDX8bsbAQBzgQ5E=
Loading
Loading