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.
- 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
- Go (>=1.20) – Install Go
- Docker & Docker Compose – Install Docker
- SendGrid API Key – Create a SendGrid account
-
Clone the Repository
git clone https://github.com/satyamkale27/Go-social.git cd Go-social -
Set Up Environment Variables
Create a
.envrcfile 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
-
Start PostgreSQL Database
docker-compose up -d
- Install Go Dependencies: Run
go mod tidyto install and clean up dependencies. - Run
go install github.com/air-verse/air@latestfor live reloading(optional) - Run
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
-
Run Database Migrations
source .envrc make migrate -up -
Build and Run the Application
go build -o bin/main ./cmd/api
-
Access the API
The backend API is available at:
http://localhost:8080
-
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" }
- 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
-
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
-
POST
v1/posts/{postId}/comments– Add a comment{ "content": "This is a comment." } -
GET
v1/posts/{postId}/comments– Get all comments on a post
- 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 (ascordesc)tags: Filter by tags (comma-separated)search: Search by title or content
- Query Parameters:
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.