{"id":13582478,"url":"https://github.com/antelman107/net-wait-go","last_synced_at":"2025-06-19T08:10:38.907Z","repository":{"id":49212252,"uuid":"276103106","full_name":"antelman107/net-wait-go","owner":"antelman107","description":"Utility and GO library that helps wait for network port to open on server side","archived":false,"fork":false,"pushed_at":"2024-04-04T12:33:37.000Z","size":2581,"stargazers_count":35,"open_issues_count":3,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-05T22:41:26.016Z","etag":null,"topics":["bash","docker","go","golang","wait","wait-for-it"],"latest_commit_sha":null,"homepage":"https://golangforall.com/en/post/net-wait-go.html","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/antelman107.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}},"created_at":"2020-06-30T13:14:23.000Z","updated_at":"2024-09-03T12:56:16.000Z","dependencies_parsed_at":"2024-04-04T13:47:04.431Z","dependency_job_id":"304a495f-c7df-4d58-8a4b-c492d1f6bb45","html_url":"https://github.com/antelman107/net-wait-go","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antelman107%2Fnet-wait-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antelman107%2Fnet-wait-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antelman107%2Fnet-wait-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/antelman107%2Fnet-wait-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/antelman107","download_url":"https://codeload.github.com/antelman107/net-wait-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":231984256,"owners_count":18456018,"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":["bash","docker","go","golang","wait","wait-for-it"],"created_at":"2024-08-01T15:02:45.261Z","updated_at":"2024-12-31T12:24:08.264Z","avatar_url":"https://github.com/antelman107.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"![alt text](https://github.com/antelman107/net-wait-go/blob/master/tube2.svg?raw=true)\n\n# What is it?\nBoth utility and GO package to wait for port to open (TCP, UDP).\n\n# Why do we need it?\n\nIn dockerized applications usually we deploy \nseveral containers with the main program container.\n\nWe need to know if containers are started, so we\ncan continue to execute our program or fail it after some deadline.\n\nThere are a lot of examples through the internet \nthat advise us to use several `bash` commands like `nc`, `timeout`, `curl`. But what if we have GO program minimal docker image `from scratch` that does not have `bash`? We could use this package as library in our program - just put couple lines of code to check if some ports are available.\n\nBut also this package can be donwloaded as utility and used from command line.\n\n# Library usage\n\n## Simple\n```GO\nimport \"github.com/antelman107/net-wait-go/wait\"\n\nif !wait.New().Do([]string{\"postgres:5432\"}) {\n    logger.Error(\"db is not available\")\n    return\n}\n```\n\n## All optional settings definition\n```GO\nimport \"github.com/antelman107/net-wait-go/wait\"\n\nif !wait.New(\n      wait.WithProto(\"tcp\"),\n      wait.WithWait(200*time.Millisecond),\n      wait.WithBreak(50*time.Millisecond),\n      wait.WithDeadline(15*time.Second),\n      wait.WithDebug(true),\n).Do([]string{\"postgres:5432\"}) {\n    logger.Error(\"db is not available\")\n    return\n}\n```\n\n# Utility usage\n\n```bash\n$ go get github.com/antelman107/net-wait-go\n$ net-wait-go\n\n  -addrs string\n        address:port(,address:port,address:port,...)\n  -deadline uint\n        deadline in milliseconds (default 10000)\n  -debug\n        debug messages toggler\n  -delay uint\n        break between requests in milliseconds (default 50)\n  -packet string\n        UDP packet to be sent\n  -proto string\n        tcp (default \"tcp\")\n  -wait uint\n        delay of single request in milliseconds (default 100)\n```\n\n## 1 service check\n```bash\nnet-wait-go -addrs ya.ru:443 -debug true\n\n2020/06/30 18:07:38 ya.ru:443 is OK\n\n# return code is 0\n```\n\n## 2 services check\n```bash\nnet-wait-go -addrs ya.ru:443,yandex.ru:443 -debug true\n\n2020/06/30 18:09:24 yandex.ru:443 is OK\n2020/06/30 18:09:24 ya.ru:443 is OK\n\n# return code is 0 (if all services are OK)\n```\n\n## 2 services check (fail)\n```bash\nnet-wait-go -addrs ya.ru:445,yandex.ru:445 -debug true\n\n2020/06/30 18:09:24 yandex.ru:445 is FAILED\n2020/06/30 18:09:24 ya.ru:445 is is FAILED\n...\n# return code is 1 (if at least 1 service is failed)\n```\n\n# UDP support\nSince UDP as protocol does not provide connection between a server and clients,\nit is not supported in the most of popular\nutilities:\n - `wait-for-it` issue - https://github.com/vishnubob/wait-for-it/issues/29)\n - `netcat` (`nc`) has following note in its manual page:\n     ```\n    CAVEATS\n           UDP port scans will always succeed (i.e. report the port as open)\n    ```\n   \n`net-wait-go` provides UDP support, working following way:\n - sends a meaningful packet to the server\n - waits for a message back from the server (1 byte at least)\n \n## UDP library usage example\nCounter Strike game server is accessible via UDP.\nLet's check random Counter Strike server\n by sending A2S_INFO packet (https://developer.valvesoftware.com/wiki/Server_queries#A2S_INFO)\n\n ```go\ne := wait.New(\n      wait.WithProto(\"udp\"),\n      wait.WithUDPPacket([]byte{\n            0xFF, 0xFF, 0xFF, 0xFF, 0x54, 0x53, \n            0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, \n            0x45, 0x6E, 0x67, 0x69, 0x6E, 0x65, \n            0x20, 0x51, 0x75, 0x65, 0x72, 0x79, \n            0x00}),\n      wait.WithDebug(true),\n      wait.WithDeadline(time.Second*2),\n)\nif !e.Do([]string{\"46.174.53.245:27015\",\"185.158.113.136:27015\"}) {\n      logger.Error(\"udp services are not available\")\n      return\n} \n```\n\n`WithUDPPacket` value here is the base64-encoded A2S_INFO packet, which is documented here - https://github.com/wriley/steamserverinfo/blob/master/steamserverinfo.go#L133\n\n\n## UDP utility usage example \n\n```bash\nnet-wait-go -proto udp -addrs 46.174.53.245:27015,185.158.113.136:27015 -packet '/////1RTb3VyY2UgRW5naW5lIFF1ZXJ5AA==' -debug true\n \n2020/07/12 15:13:25 udp 185.158.113.136:27015 is OK\n2020/07/12 15:13:25 udp 46.174.53.245:27015 is OK\n\n# return code is 0\n```\n\n`-packet` value here is the base64-encoded A2S_INFO packet (see above). Since it is problematic to pass\nbinary value in command line, base64 encoding for \n`packet` parameter is chosen.\n\n\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantelman107%2Fnet-wait-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fantelman107%2Fnet-wait-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fantelman107%2Fnet-wait-go/lists"}