This is a gRPC-based Task Manager service built with Go, PostgreSQL, and Protobuf. It provides functionalities to create, read, update, and delete tasks in a PostgreSQL database using a gRPC interface.
- Go (version 1.17 or higher).
- PostgreSQL installed and running.
psql
configured in thePATH
environment variable for command-line operations.protoc
(Protocol Buffers compiler) installed for generating Go files from.proto
definitions.
git clone https://github.com/your-username/task-manager.git
cd task-manager
-
Connect to PostgreSQL as an admin user (e.g.,
postgres
):psql -U postgres
-
Create the database
task_manager
:CREATE DATABASE task_manager;
-
Create the user
task_user
with a password:CREATE USER task_user WITH PASSWORD 'task_password';
-
Grant all privileges on the
task_manager
database totask_user
:GRANT ALL PRIVILEGES ON DATABASE task_manager TO task_user;
-
Grant usage and create permissions on the
public
schema totask_user
:GRANT USAGE ON SCHEMA public TO task_user; GRANT CREATE ON SCHEMA public TO task_user;
-
Connect to the
task_manager
database astask_user
:psql -U task_user -d task_manager
-
Create the
tasks
table:CREATE TABLE tasks ( id SERIAL PRIMARY KEY, title VARCHAR(255) NOT NULL, description TEXT, status VARCHAR(50) NOT NULL DEFAULT 'pending', created_at TIMESTAMP NOT NULL DEFAULT NOW() );
Make sure you're in the proto
directory:
cd proto
Run the following command to generate the Go files:
protoc --go_out=../pkg --go-grpc_out=../pkg task_manager.proto
Check that the database connection string in main.go
is correct:
connStr := "user=task_user password=task_password dbname=task_manager sslmode=disable"
Start the server by running the following command:
go run cmd/main.go
You should see a message like:
gRPC server listening on port 50051...
-
Import the
task_manager.proto
file in Postman and configure the connection tolocalhost:50051
. -
Use the
CreateTask
method with the following payload:{ "title": "New Task", "description": "This is a test task from Postman" }
-
You should receive a response like:
{ "id": 1, "success": true, "message": "Task created successfully" }
This project uses gRPC for communication and PostgreSQL for data storage. For more information on how to extend the service or modify it, check the official gRPC documentation and PostgreSQL documentation.