↘ API for product management, with user system, authentication and authorization. ↙
Routes that only the admin user can access are marked with the flag ⛔
- OAuth Basic Authentication Endpoint
- Authorization from JWT Bearer Token
- Create User
- Get User
- Update User (username, password)
- List Users ⛔
- Delete User (soft delete, hard delete) ⛔
- Recovery User ⛔
- Active/Deactive User ⛔
- Create Product
- Get Product
- List Products
- Update Product
- Delete Product (soft delete, hard delete) ⛔
cp -r docs/samples/*.sample $PWD; for i in *.sample ; do mv "$i" "$(basename "$i" .sample)" ; done && source envs.sh
Note
When you restart the terminal session, you will need to run the source envs.sh
command again.
- 🔑 Genereta RSA private key for assign JWT token
openssl genpkey -out rsa_pvkey.pem -algorithm RSA -pkeyopt rsa_keygen_bits:2048
# using docker container, running on http://localhost:3000
docker compose up -d
# using direct in terminal, running on http://localhost:5000
docker compose up -d go_product_api_db go_product_api_cache
go run cmd/main.go
- 🧩 Pre commit (For development only)
pip intall pre-commit # install pre-commit with python pip
go install golang.org/x/tools/cmd/goimports@latest # pre-commit hook
go install github.com/golangci/golangci-lint/cmd/[email protected] # pre-commit hook
pre-commit install # install pre-commit hooks
curl --request POST \
--url http://localhost:3000/v1/users \
--header 'Content-Type: application/json' \
--data '{
"username": "Anonymous1",
"email": "[email protected]",
"password": "mypassword123"
}'
Important
By default, users are created with active
set to false
, run the following command to make the admin
user active and the system unlock:
docker exec -ti $DB_CONTAINER_NAME psql -U $DB_USER \
-d $DB_NAME -c "UPDATE public.users SET active = true, is_admin = true WHERE id = 1;"
curl --request POST \
--url http://localhost:3000/v1/oauth2/token \
--header 'Content-Type: application/json' \
--data '{
"email": "[email protected]",
"password": "mypassword123",
"grant_type": "client_credentials"
}'
- K6 simple tests
# build container image
docker build tests/performance -t go_product_api_k6
# run spike_k6_test.js example
docker run --network go-product-api_default --rm go_product_api_k6 run spike_k6_test.js
- Unit tests
WIP
- JSON format output log
- Memory in cache (Redis)
- Rate limiting by IP
- Database auto migrations