In this version, gateways includes database information.
And this breaks DIP (Dependency Inversion Principal)
Not a perfect Clean Architecture.
To Start DB
make up
To Start API Server
make start
To start DB
docker-compose up
To start api server
go run .
You can see details in /infrastructures/rounter.go
and /adapters/gateways/user_gateways.go
End point | Method |
---|---|
~/users/all | GET |
~/users/range?start=[id]&end=[id] | GET |
~/users?ids[0]=[id]&ids[1]=[id]&.... | GET |
~/user/:id | GET |
- ~/users/all
To get all users. - ~/users/range?start=[id]&end=[id]
To get users in a certain ids range. - ~/users?ids[0]=[id]&ids[1]=[id]&....
To get users according to ids
Ex) ~/users?ids[0]=1&ids[1]=3&ids[2]=8 - ~/user/:id
To get a user
- Make a go structure in
/entities
- Make port and interactor in
/usecases
- Make controllers, gateways and presenters in
/adaptors
- Make API endpoint in
/infrastructures
- Run
migrate create -ext sql -dir database/migrations -seq [sql file name]
-
Edit
database/[version]-migrations/[sql_file_name].up.sql
and~.down.sql
-
Run
${POSTGRESQL_URL} = 'postgres://user:pass@url:port/tablename'
migrate -path database/migrations -database ${POSTGRESQL_URL} up
When the migration is failed, your schema is recoded as "dirty". Anyway, fix your migration and Run
To change your schema clear.
migrate -path database/migrations -database ${POSTGRESQL_URL} force 1
And downgrade your tables
migrate -path database/migrations -database ${POSTGRESQL_URL} down 1
And upgrade 1
migrate -path database/migrations -database ${POSTGRESQL_URL} up 1
4.Run
To get a go structure from database schema.
See /models/~
sqlboiler psql