I built this solution from scratch here as a foundation for my future projects.
NOTE: The code is rough, buggy, and not production-ready—use at your own risk.
- Router
- Filter
- Interface
- Middleware
- Pagination
- Soft-delete
- Authorization
- Authentication
- Use
PATCHverb - Database indexes
- Password hashing
- Database migration
- Input validation + sanitization
- Context for database query and middleware
- Concurrency for independent database query (get all users, count users)
- Use pointer for boolean to differentiate between "not provided" and "explicitly false" in Go
- Basic authentication and authorization
- CRUD operations
# public
POST /auth/register
POST /auth/login
GET /users/all
- filter email, status
- pagination
- TODO: only admin can get all users including inactive
GET /users/{id}
# auth
PATCH /users/{id}
- user update their profile, like email, bio, etc.
PATCH /users/{id}/password
- user update their password, must provide old password
PATCH /users/{id}/status
- user deactivate her account (soft-delete)
- only admin can activate an account
# authz
DELETE /users/{id}
- admin hard-delete an account
# TODO
PATCH /users/{id}/role
- admin change other user's role to admin- Users:
- id
- role
idx - email - unique
- password
- is_active- Add
PATCH /users/{id}/role: admin change other user's role to admin - Add unit tests
Run build make command with tests
make allBuild the application
make buildRun the application
make runCreate DB container
make docker-runShutdown DB Container
make docker-downDB Integrations Test:
make itestLive reload the application:
make watchRun the test suite:
make testClean up binary from the last build:
make clean