- Pull & run docker iamge
docker run -it -d -p 5432:5432 --name postgres-local -e POSTGRES_PASSWORD=password postgres
- Go into docker container
docker exec -it postgres-local bash
- Login pg
psql -h localhost -U postgres
- Create user
CREATE USER "user_login" WITH PASSWORD 'password';
ALTER ROLE "user_login" WITH SUPERUSER;
- Create Database
CREATE DATABASE dbtest;
- Export ENV
export PG_HOST=127.0.0.1
export PG_PORT=5432
export PG_USER=user_login
export PG_PASS=password
export PG_DB=dbtest
export PORT=9090
- Insert test data, please take a look for db.sql
- Install go packages
go get -u ./...
- Init go vendor for go modules management
go mod vendor
- Run app
go run main.go
- No one uses http GET for login.
- Instead of GET to POST.
- Change NoSQL Live to Postgres
3.Update columns.
- No one uses ID of column with TEXT type, expect ony NoSQL using uuid -> Change to bigserialize
- Change created_date from TEXT to timestamp and set default and create INDEX for it
- Change user_id of task to INT8 and update INDEX for it
- Add a username into Users table and check UNIQUE
- No one exposes raw password, which is very risk. I applied bcrypt hash to encrypt password.
- DDD architecture
- Currently, I applied DDD (3 layers) and used self-container components, which helps me narrow down business logic in a single directory
- Domain contains endpoints and logic core
- Infrastructure contains drivers, services, providers, middleware...etc
- Pkgs contains utils, common, re-useable codes
- Apply unit test