{"id":24121245,"url":"https://github.com/jojoarianto/go-chat-app-websocket","last_synced_at":"2025-10-04T11:57:01.563Z","repository":{"id":57575084,"uuid":"169964285","full_name":"jojoarianto/go-chat-app-websocket","owner":"jojoarianto","description":"Simple chat app using go websocket","archived":false,"fork":false,"pushed_at":"2019-02-11T09:43:59.000Z","size":208,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T22:10:13.502Z","etag":null,"topics":["chat","go","gorilla-websocket","websocket"],"latest_commit_sha":null,"homepage":"","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/jojoarianto.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}},"created_at":"2019-02-10T10:01:56.000Z","updated_at":"2024-11-24T06:50:22.000Z","dependencies_parsed_at":"2022-09-18T06:34:22.845Z","dependency_job_id":null,"html_url":"https://github.com/jojoarianto/go-chat-app-websocket","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jojoarianto/go-chat-app-websocket","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jojoarianto%2Fgo-chat-app-websocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jojoarianto%2Fgo-chat-app-websocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jojoarianto%2Fgo-chat-app-websocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jojoarianto%2Fgo-chat-app-websocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jojoarianto","download_url":"https://codeload.github.com/jojoarianto/go-chat-app-websocket/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jojoarianto%2Fgo-chat-app-websocket/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278308622,"owners_count":25965654,"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-04T02:00:05.491Z","response_time":63,"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":["chat","go","gorilla-websocket","websocket"],"created_at":"2025-01-11T10:51:10.713Z","updated_at":"2025-10-04T11:57:01.520Z","avatar_url":"https://github.com/jojoarianto.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Chat APP\n\nSimple chat app using gorilla websocket\n\n\u003e Demo [screenshot app](#demo-screenshot) \n\n## Goal\n\n- [X] [API for sending a message](#api-endpoint-for-sending-a-message)\n- [X] [API for collect message that has been sent out](#api-endpoint-for-collect-message-that-has-been-sent-out)\n- [X] [API for display message in real time](#display-message-on-websocket-realtime)\n\n## Installation \u0026 Run\n\nFirst, Make sure you have set up \\$GOPATH.\n\n```bash\n# Download this project\ngo get github.com/jojoarianto/go-chat-app-websocket\n\n# It's take several minute to download project\n```\n\nRun\n\n```bash\n# move to project directory\ncd $GOPATH/src/github.com/jojoarianto/go-chat-app-websocket\n\n# run golang project\ngo run main.go\n\n# Visit : http://localhost:8000/\n```\n\n## Structure Design\n\n- Domain\n  - Define struct represent mapping to data model\n      - message.go\n- Interfaces\n  - HTTP handler\n  - Websocket handler\n  - Respond handler\n- Static\n  - Static assets\n      - .png .jpeg\n      - .css \n  - index.html\n\n## Model Data\nMessage (Pesan)\n```go \ntype Message struct {\n\tID             xid.ID       `json:\"id\"`\n\tSender         string       `json:\"sender,omitempty\"`\n\tContentMessage string       `json:\"content_message\"`\n\tCreatedAt      time.Time    `json:\"created_at\"`\n}\n```\n\n### API endpoint for sending a message\n\n\u003e `POST` localhost:8000/sent\n\n#### Request with data json \n```json\n{\n    \"content_message\": \"Hi Chat App\"\n}\n```\n\nor using curl\n\n```bash\ncurl --request POST \\\n  --url http://localhost:8000/sent \\\n  --header 'content-type: application/json' \\\n  --data '{\n  \t    \"content_message\": \"Hi Chat App\"\n    }'\n```\n\n#### Respond\n```json\n{\n  \"id\": \"bhgi9mml0s15jsg5c260\",\n  \"sender\": \"Anonim\",\n  \"content_message\": \"Hi Chat App\",\n  \"created_at\": \"2019-02-11T14:31:38.711328+07:00\"\n}\n```\n\n### API endpoint for collect message that has been sent out\n\n\u003e `GET` localhost:8000/sent\n\n#### Request with hit http://localhost:8000/sent\n\nor using curl\n\n```bash\ncurl --request GET \\\n  --url http://localhost:8000/sent\n```\n#### Respond\n\n```json\n[\n  ...\n  {\n    \"id\": \"bhgibael0s15jsg5c27g\",\n    \"sender\": \"Anonim\",\n    \"content_message\": \"Ada apa\",\n    \"created_at\": \"2019-02-11T14:35:05.886498+07:00\"\n  },\n  {\n    \"id\": \"bhgibcml0s15jsg5c28g\",\n    \"sender\": \"Anonim\",\n    \"content_message\": \"tidak ada apa apa\",\n    \"created_at\": \"2019-02-11T14:35:14.373446+07:00\"\n  }\n  ...\n]\n```\n\n### Display Message on Websocket (Realtime)\n\n\u003e `Websocket` ws://localhost:8000/ws\n\n#### Open on browser http://localhost:8000\n\nor using curl\n\n```bash\ncurl --include \\\n     --no-buffer \\\n     --header \"Connection: Upgrade\" \\\n     --header \"Upgrade: websocket\" \\\n     --header \"Host: localhost:8000\" \\\n     --header \"Origin: http://localhost:8000\" \\\n     --header \"Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==\" \\\n     --header \"Sec-WebSocket-Version: 13\" \\\n     http://localhost:8000/ws\n```\n\n## Unit Test\n\n```bash\n# move to interfaces folder\ncd $GOPATH/src/github.com/jojoarianto/go-chat-app-websocket/interfaces\n\n# run golang test\ngo test -V\n```\n\n## Libraries\n- Gorilla Websocket from https://github.com/gorilla/websocket\n- HttpRouter from https://github.com/julienschmidt/httprouter\n- Globally Unique ID Generator from https://github.com/rs/xid\n- End-to-end HTTP and REST API testing from https://github.com/gavv/httpexpect\n\n## Demo Screenshot\n\n![demo-png](https://user-images.githubusercontent.com/5858756/52549176-79d10880-2e04-11e9-9c09-902bf5db00bb.png)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjojoarianto%2Fgo-chat-app-websocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjojoarianto%2Fgo-chat-app-websocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjojoarianto%2Fgo-chat-app-websocket/lists"}