Skip to content

comrade001/task-manager-grpc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Manager gRPC Service

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.

Prerequisites

  1. Go (version 1.17 or higher).
  2. PostgreSQL installed and running.
  3. psql configured in the PATH environment variable for command-line operations.
  4. protoc (Protocol Buffers compiler) installed for generating Go files from .proto definitions.

Getting Started

Step 1: Clone the repository

git clone https://github.com/your-username/task-manager.git
cd task-manager

Step 2: Set up the PostgreSQL database

  1. Connect to PostgreSQL as an admin user (e.g., postgres):

    psql -U postgres
  2. Create the database task_manager:

    CREATE DATABASE task_manager;
  3. Create the user task_user with a password:

    CREATE USER task_user WITH PASSWORD 'task_password';
  4. Grant all privileges on the task_manager database to task_user:

    GRANT ALL PRIVILEGES ON DATABASE task_manager TO task_user;
  5. Grant usage and create permissions on the public schema to task_user:

    GRANT USAGE ON SCHEMA public TO task_user;
    GRANT CREATE ON SCHEMA public TO task_user;

Step 3: Create the tasks table

  1. Connect to the task_manager database as task_user:

    psql -U task_user -d task_manager
  2. 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()
    );

Step 4: Generate Go files from the .proto file

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

Step 5: Update the configuration in main.go

Check that the database connection string in main.go is correct:

connStr := "user=task_user password=task_password dbname=task_manager sslmode=disable"

Step 6: Run the gRPC server

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...

Step 7: Test the service with Postman or grpcurl

  1. Import the task_manager.proto file in Postman and configure the connection to localhost:50051.

  2. Use the CreateTask method with the following payload:

    {
      "title": "New Task",
      "description": "This is a test task from Postman"
    }
  3. You should receive a response like:

    {
      "id": 1,
      "success": true,
      "message": "Task created successfully"
    }

Additional Information

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages