This is a simple user management system written in Go. It provides an API to manage user permissions in different contexts.
- Get user permissions
- Set new permissions for a user
- Remove existing permissions
- Go 1.16 or higher
- Docker (optional, for running a database container)
- Clone the repository:
git clone https://github.com/yourusername/user-management.git
cd user-management
- Install dependencies:
go mod tidy
- Create a
.env
file in the root of the project and set the following environment variables:
HOST=your_db_host
PORT=your_db_port
USERNAME=your_db_username
PASSWORD=your_db_password
- (Optional) Run a database container using Docker:
docker run --name user_management_db -e POSTGRES_USER=your_db_username -e POSTGRES_PASSWORD=your_db_password -e POSTGRES_DB=user_management_db -p 5432:5432 -d postgres
- Run the application:
go run main.go
The server will start on port 8080.
GET /permissions/{userID}
Fetches permissions for a user.
userID
(path): The ID of the user whose permissions are being fetched.
curl -X GET http://localhost:8080/permissions/1
[
{
"id": 1,
"userId": 1,
"contextId": 100,
"read": true,
"write": false
},
{
"id": 2,
"userId": 1,
"contextId": 101,
"read": true,
"write": true
}
]
POST /permissions
Sets a new permission for a user.
{
"userId": 1,
"contextId": 100,
"read": true,
"write": false
}
curl -X POST http://localhost:8080/permissions -H "Content-Type: application/json" -d '{"userId": 1, "contextId": 100, "read": true, "write": false}'
201 Created
DELETE /permissions/{permissionID}
Removes a permission by ID.
permissionID
(path): The ID of the permission to be removed.
curl -X DELETE http://localhost:8080/permissions/1
204 No Content