{"id":22125520,"url":"https://github.com/youstinus/websocket-task","last_synced_at":"2025-03-24T08:15:26.276Z","repository":{"id":114220542,"uuid":"441680132","full_name":"youstinus/websocket-task","owner":"youstinus","description":"API that upgrades connection to use websocket. Contains server and client and testing how they communicate","archived":false,"fork":false,"pushed_at":"2021-12-25T13:09:13.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-29T13:27:19.435Z","etag":null,"topics":["api","client","go","golang","server","websocket","websocket-client","websocket-server"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/youstinus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2021-12-25T13:00:57.000Z","updated_at":"2021-12-25T13:11:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"b432e813-b557-4def-9c7c-ca0d135b7126","html_url":"https://github.com/youstinus/websocket-task","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youstinus%2Fwebsocket-task","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youstinus%2Fwebsocket-task/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youstinus%2Fwebsocket-task/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youstinus%2Fwebsocket-task/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/youstinus","download_url":"https://codeload.github.com/youstinus/websocket-task/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245232885,"owners_count":20581701,"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","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":["api","client","go","golang","server","websocket","websocket-client","websocket-server"],"created_at":"2024-12-01T16:33:07.280Z","updated_at":"2025-03-24T08:15:26.256Z","avatar_url":"https://github.com/youstinus.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Websocket Test API\n\n\n### How to execute\n\nFirst run server using: `make run-server`.\n\nThen run many client instances with: `make run-client`.\n\nThen start typing in clients, and when you enter, text will be sent to server and returned as response.\n\nTry yourself. Replaces question marks `?` with other symbol `!`.\n\nAll methods are in `main.go` file\n\nApp can be compiled with `go build main.go`\n\nApp can be tested with `go test`\n\nApp can be executed with `go run main.go`\n\nOptional parameter can be added port. Example `go run main.go -port=8080` or `server -port 8080`\n\nType `server --help` for help\n\n\n#### How it works\n\nThe server opens given or default port and listens for HTTP requests.\n\nCreated two endpoints. One is root to check if the server works.\n\nSecond is `/ws`. Expects for connection upgrade from HTTP to a WebSocket and waits for messages.\n\nReceived messages validated if it is text and all question marks replaced with exclamation marks.\n\nProcessed message is sent back to the client.\n\nThe connection closes when received not a valid message of client closes the connection.\n\nThe server should work in any environment\n\n\n\nClient initializes http protocol change into WebSocket protocol.\n\nThe client sends all messages entered from console.\n\nReceives processed messages and prints out to console.\n\n\n\nI have chosen these approaches because they are documented by golang developers.\n\ngorilla/websocket is mostly used in WebAPIs.\n\nwebsocket.DefaultDialer.Dial method inside client automatically initializes http protocol change to WebSocket.\n\nUnit tests not well done. It is possible to cover more situations.\n\n\n#### References used\n\nhttps://yalantis.com/blog/how-to-build-websockets-in-go/\n\nhttps://quii.gitbook.io/learn-go-with-tests/build-an-application/websockets\n\nhttps://stackoverflow.com/questions/47637308/create-unit-test-for-ws-in-golang\n\nhttps://www.digitalocean.com/community/tutorials/how-to-build-go-executables-for-multiple-platforms-on-ubuntu-16-04\n\nhttps://stackoverflow.com/questions/52964304/websocket-set-protocol-and-origin\n\nhttps://www.geeksforgeeks.org/http-headers-content-type/\n\nhttps://codeburst.io/unit-testing-for-rest-apis-in-go-86c70dada52d\n\nhttps://www.youtube.com/watch?v=ttKgBttwzrg\n\nhttps://stackoverflow.com/questions/55536439/how-can-i-upgrade-a-client-http-connection-to-websockets-in-golang-after-sending\n\nhttps://golang.org/doc/articles/wiki/\n\nhttps://stackoverflow.com/questions/55094133/how-to-send-some-event-update-from-http-handler-to-a-websocket-handler\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoustinus%2Fwebsocket-task","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoustinus%2Fwebsocket-task","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoustinus%2Fwebsocket-task/lists"}