{"id":31813954,"url":"https://github.com/asm2212/gochat","last_synced_at":"2025-10-11T08:23:09.993Z","repository":{"id":303069085,"uuid":"1014300731","full_name":"asm2212/gochat","owner":"asm2212","description":null,"archived":false,"fork":false,"pushed_at":"2025-07-05T13:01:47.000Z","size":7,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-05T14:24:02.425Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/asm2212.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-05T12:50:52.000Z","updated_at":"2025-07-05T13:01:50.000Z","dependencies_parsed_at":"2025-07-05T14:24:09.027Z","dependency_job_id":"825fdbed-bfcc-4adc-9de6-655da25ee9ba","html_url":"https://github.com/asm2212/gochat","commit_stats":null,"previous_names":["asm2212/gochat"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/asm2212/gochat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asm2212%2Fgochat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asm2212%2Fgochat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asm2212%2Fgochat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asm2212%2Fgochat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/asm2212","download_url":"https://codeload.github.com/asm2212/gochat/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/asm2212%2Fgochat/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006762,"owners_count":26084148,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-11T08:23:07.649Z","updated_at":"2025-10-11T08:23:09.987Z","avatar_url":"https://github.com/asm2212.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gochat\n\nA Go backend for a Telegram-style chat system.\n\n**Features:**\n- User signup \u0026 login (JWT, bcrypt)\n- Direct one-to-one messages\n- Group chat (create, send, fetch)\n- Global broadcast messaging\n\n---\n\n## 📁 Project Structure\n\n```\ngochat/\n  main.go             # Entry point\n  internal/\n    api.go            # HTTP handlers\n    auth.go           # JWT middleware\n    user.go           # User logic\n    chat.go           # Messaging logic\n    model.go          # Data models\n    redis.go          # Redis connection\n  go.mod\n  README.md\n```\n\n---\n\n## 🚀 Quick Start\n\n1. **Clone the repository**\n    ```sh\n    git clone https://github.com/asm2212/gochat.git\n    cd gochat\n    ```\n\n2. **Start a Redis server**  \n   You must have Redis running on your local machine (`localhost:6379`).\n   - You can [download and run Redis](https://redis.io/download/) for your operating system.\n\n3. **Install Go dependencies**\n    ```sh\n    go mod tidy\n    ```\n\n4. **Run the server**\n    ```sh\n    go run .\n    ```\n    The server will start on port `:8080`.\n\n---\n\n## 📖 API Endpoints\n\n_All endpoints except `/signup` and `/login` require JWT authentication.  \nProvide the token in the `Authorization: Bearer \u003ctoken\u003e` HTTP header._\n\n---\n\n### 🔒 Authentication\n\n#### Sign Up\n\n- **Endpoint:** `POST /signup`\n- **Request Body:**\n    ```json\n    {\n      \"username\": \"your_username\",\n      \"password\": \"your_password\"\n    }\n    ```\n- **Response:**\n    - `201 Created` on success:  \n      ```json\n      { \"message\": \"user registered\" }\n      ```\n    - `409 Conflict` if user exists:  \n      ```json\n      { \"error\": \"username already exists\" }\n      ```\n\n#### Login\n\n- **Endpoint:** `POST /login`\n- **Request Body:**\n    ```json\n    {\n      \"username\": \"your_username\",\n      \"password\": \"your_password\"\n    }\n    ```\n- **Response:**\n    - `200 OK` on success:  \n      ```json\n      { \"token\": \"\u003cJWT_TOKEN\u003e\" }\n      ```\n    - `401 Unauthorized` on failure:  \n      ```json\n      { \"error\": \"invalid credentials\" }\n      ```\n\n---\n\n### 💬 Direct Messages\n\n#### Send a Direct Message\n\n- **Endpoint:** `POST /dm/send`\n- **Headers:**  \n  `Authorization: Bearer \u003ctoken\u003e`\n- **Request Body:**\n    ```json\n    {\n      \"to\": \"recipient_username\",\n      \"content\": \"Hello!\"\n    }\n    ```\n- **Response:**\n    - `200 OK`  \n      ```json\n      { \"message\": \"sent\" }\n      ```\n    - `500 Internal Server Error`  \n      ```json\n      { \"error\": \"...\" }\n      ```\n\n#### Fetch Direct Message History\n\n- **Endpoint:** `GET /dm/history?user=recipient_username`\n- **Headers:**  \n  `Authorization: Bearer \u003ctoken\u003e`\n- **Response:**\n    - `200 OK`  \n      ```json\n      [\n        {\n          \"id\": \"b7c9...\",\n          \"from\": \"alice\",\n          \"to\": \"bob\",\n          \"content\": \"Hello Bob!\",\n          \"type\": \"direct\",\n          \"timestamp\": \"2025-07-06T05:00:00Z\"\n        },\n        ...\n      ]\n      ```\n    - `500 Internal Server Error`  \n      ```json\n      { \"error\": \"...\" }\n      ```\n\n---\n\n### 👥 Group Chat\n\n#### Create a Group\n\n- **Endpoint:** `POST /group/create`\n- **Headers:**  \n  `Authorization: Bearer \u003ctoken\u003e`\n- **Request Body:**\n    ```json\n    {\n      \"group\": \"group_name\"\n    }\n    ```\n- **Response:**\n    - `201 Created`  \n      ```json\n      { \"message\": \"group created\" }\n      ```\n    - `500 Internal Server Error`  \n      ```json\n      { \"error\": \"...\" }\n      ```\n\n#### Send a Group Message\n\n- **Endpoint:** `POST /group/send`\n- **Headers:**  \n  `Authorization: Bearer \u003ctoken\u003e`\n- **Request Body:**\n    ```json\n    {\n      \"group\": \"group_name\",\n      \"content\": \"Group message!\"\n    }\n    ```\n- **Response:**\n    - `200 OK`  \n      ```json\n      { \"message\": \"sent\" }\n      ```\n    - `500 Internal Server Error`  \n      ```json\n      { \"error\": \"...\" }\n      ```\n\n#### Fetch Group Chat History\n\n- **Endpoint:** `GET /group/history?group=group_name`\n- **Headers:**  \n  `Authorization: Bearer \u003ctoken\u003e`\n- **Response:**\n    - `200 OK`  \n      ```json\n      [\n        {\n          \"id\": \"a1b2...\",\n          \"from\": \"alice\",\n          \"group\": \"mygroup\",\n          \"content\": \"Hi everyone\",\n          \"type\": \"group\",\n          \"timestamp\": \"2025-07-06T05:00:00Z\"\n        },\n        ...\n      ]\n      ```\n    - `500 Internal Server Error`  \n      ```json\n      { \"error\": \"...\" }\n      ```\n\n---\n\n### 📢 Broadcast\n\n#### Send a Broadcast Message\n\n- **Endpoint:** `POST /broadcast/send`\n- **Headers:**  \n  `Authorization: Bearer \u003ctoken\u003e`\n- **Request Body:**\n    ```json\n    {\n      \"content\": \"Message to everyone!\"\n    }\n    ```\n- **Response:**\n    - `200 OK`  \n      ```json\n      { \"message\": \"broadcasted\" }\n      ```\n    - `500 Internal Server Error`  \n      ```json\n      { \"error\": \"...\" }\n      ```\n\n#### Fetch Broadcast Messages\n\n- **Endpoint:** `GET /broadcast/history`\n- **Headers:**  \n  `Authorization: Bearer \u003ctoken\u003e`\n- **Response:**\n    - `200 OK`  \n      ```json\n      [\n        {\n          \"id\": \"xxxx\",\n          \"from\": \"alice\",\n          \"content\": \"Hello all!\",\n          \"type\": \"broadcast\",\n          \"timestamp\": \"2025-07-06T05:00:00Z\"\n        },\n        ...\n      ]\n      ```\n    - `500 Internal Server Error`  \n      ```json\n      { \"error\": \"...\" }\n      ```\n\n---\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasm2212%2Fgochat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fasm2212%2Fgochat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fasm2212%2Fgochat/lists"}