This project is a web-based forum that enables communication between users through posts and comments. It allows user authentication, post categorization, interaction via likes/dislikes, and filtering functionalities. The back-end is built using Go, with SQLite as the database, and the project is containerized using Docker.
-
Users can register and log in to the forum.
-
Registration requires:
-
A unique email (duplicate emails return an error).
-
A username.
-
A password (encrypted using bcrypt).
-
-
Login session management with cookies (session expiration included).
-
Each user can only have one active session at a time.
-
Users can upload profile pictures.
-
Only registered users can create posts and comments.
-
Posts can be categorized (customizable categories).
-
Users can attach media (images, videos, GIFs) to posts.
-
All users (registered or not) can view posts and comments.
-
Only registered users can like/dislike posts and comments.
-
Like/dislike counts are visible to all users.
-
Users can filter displayed posts by:
-
Categories (subforums based on topics).
-
Created posts (for logged-in users only).
-
Liked posts (for logged-in users only).
-
-
users (id, email, username, password, session_uuid, session_expiry, -profile_picture, content_type)
-
posts (id, user_id, title, content, category, media, content_type, created_at)
-
comments (id, post_id, user_id, content, created_at)
-
likes (id, user_id, post_id, comment_id, type)
-
CREATE TABLE users ( id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT UNIQUE NOT NULL, username TEXT NOT NULL, password TEXT NOT NULL, session_uuid TEXT, session_expiry DATETIME, profile_picture BLOB, content_type TEXT );
-
INSERT INTO users (email, username, password) VALUES ('user@example.com', 'username', 'hashed_password');
-
SELECT * FROM posts WHERE category = 'Technology';
-
POST /register – User registration.
-
POST /login – User login.
-
GET /logout – End user session.
-
POST /upload-profile – Upload user profile picture.
-
GET /posts – Retrieve all posts.
-
POST /posts – Create a new post (authenticated users only).
-
GET /posts/{id} – Retrieve a specific post.
-
POST /posts/{id}/comment – Add a comment to a post.
-
GET /comments/{id}/replies – Retrieve all replies for a comment.
-
POST /likes – Like a post.(formData)
-
POST /likes – Dislike a post.(formData)
-
POST /filtered_posts – Filter posts by category.
-
GET /my_posts – Get posts created by the logged-in user.
-
GET /liked_posts – Get posts liked by the logged-in user.
-
400 Bad Request: Invalid input or missing parameters.
-
401 Unauthorized: User not logged in.
-
404 Not Found: Resource does not exist.
-
500 Internal Server Error: Unexpected server failure.
FROM golang:1.18
WORKDIR /app
COPY . .
RUN go build -o forum
CMD ["./forum"]
EXPOSE 8080
1. Build Docker Image:
docker build -t forum-app .
2. Run the Container:
docker run -p 8080:8080 forum-app
3. Testing
-
Unit tests are implemented for critical functions.
-
Use httptest for handler testing.
-
Run tests with:
go test ./...
This forum project demonstrates core web development concepts such as authentication, database interactions, and API design. It is built with Go, uses SQLite for storage, and follows best practices in handling errors and security.