Skip to content

satyamkale27/Go-social

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

103 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go-Social

Go-Social is a social networking platform built with Go. It allows users to register, create posts, follow/unfollow other users, comment on posts, and manage user roles. The project includes features like user authentication, email invitations, and role-based access control. PostgreSQL is used as the database, and SendGrid is integrated for sending email notifications.


🚀 Features

  • User registration, login, and authentication
  • Role-based access control
  • Follow/unfollow users
  • Create, update, and delete posts
  • Comment on posts
  • Email activation and invitations via SendGrid
  • User feed with pagination, search, and tag filtering

🛠 Installation Guide

Prerequisites


🔧 Setup Instructions

  1. Clone the Repository

    git clone https://github.com/satyamkale27/Go-social.git
    cd Go-social
  2. Set Up Environment Variables

    Create a .envrc file in the root directory and add the following:

    ADDR=:8080
    API_URL=http://localhost:8080
    FRONTEND_URL=http://localhost:4000
    DB_ADDR=postgres://admin:adminpassword@localhost/socialnetwork?sslmode=disable
    FROM_EMAIL=your-email@example.com
    SENDGRID_API_KEY=your-sendgrid-api-key
    TOKEN_SECRET=example
  3. Start PostgreSQL Database

    docker-compose up -d
  • Install Go Dependencies: Run go mod tidy to install and clean up dependencies.
  • Run go install github.com/air-verse/air@latest for live reloading(optional)
  • Run go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
  1. Run Database Migrations

    source .envrc
    make migrate -up
  2. Build and Run the Application

    go build -o bin/main ./cmd/api
  3. Access the API

    The backend API is available at: http://localhost:8080


📡 API Endpoints

🧑 Authentication

  • POST /v1/authentication/user – Register a new user

    {
      "username": "example",
      "email": "example@example.com",
      "password": "password123"
    }
  • POST /v1/authentication/token – Login and get token

    {
      "email": "example@example.com",
      "password": "password123"
    }

👤 User Management

  • GET v1/users/{userId} – Get user details
  • POST v1/users/{userId}/follow – Follow a user
  • POST v1/users/{userId}/unfollow – Unfollow a user
  • GET v1/users/activate/{token} – Activate a user account

📝 Posts

  • POST v1/posts – Create a new post

    {
      "title": "Post Title",
      "content": "Post Content",
      "tags": ["tag1", "tag2"]
    }
  • GET v1/posts/{postId} – Get post by ID

  • PUT v1/posts/{postId} – Update post

    {
      "title": "Updated Title",
      "content": "Updated Content"
    }
  • DELETE v1/posts/{postId} – Delete post

💬 Comments

  • POST v1/posts/{postId}/comments – Add a comment

    {
      "content": "This is a comment."
    }
  • GET v1/posts/{postId}/comments – Get all comments on a post

📰 Feed

  • GET /v1/users/feed – Get user feed
    • Query Parameters:
      • limit: Number of posts to fetch (default: 20)
      • offset: Offset for pagination (default: 0)
      • sort: Sorting order (asc or desc)
      • tags: Filter by tags (comma-separated)
      • search: Search by title or content

🧠 Conclusion

Through this project, I learned how to build a backend using Go and explored Go concepts in depth. I applied these concepts to create APIs and implement the repository pattern for clean and maintainable code. I also gained hands-on experience with PostgreSQL and database migrations. Throughout development, I wrote SQL queries, debugged various issues, and dealt with complex database errors — especially the tricky ones that occur when migrations or queries fail. This project was a valuable learning experience that strengthened my understanding of backend development in Go.

Packages

 
 
 

Contributors