shopping-cart-api
Shopping Cart API
Requirements
Setup
Prepare necessary environment by rename .env.example to .env
Run database container
docker-compose up
Run the App
Get packages
go get .
Delete unused packages if necessary
go mod tidy
Update package vendor
go mod vendor
Build the app
go build -o bin/shopping-cart -v .
Run the App
./bin/shopping-cart
Migration
Create new migration
go run app/migration/psql/main.go create AddSomeColumns
Up migration
go run app/migration/psql/main.go up
Down migration
go run app/migration/psql/main.go down
Check migration status
go run app/migration/psql/main.go status
Mockup
Generate mock
mockery --name=[interface name] --dir=[directory of interface] --output=[directory to write mocks] --filename=[name of generated file] --outpkg=[name of generated package] --structname=[name of generated struct]
mockery --name=UserRepo --dir=./core/port/ --output=./infrastructure/repo/mock/user --filename=repo.go --outpkg=user --structname=Repo
Unit Test
Run unit test
go test -v ./...
Run unit test specific function
go test -v -run TestProductCategory_Create_Success
Check coverage
go test -cover ./...
Generate coverage
go test -coverprofile=coverage ./...