{"id":24115643,"url":"https://github.com/bstrdlord/failover","last_synced_at":"2025-02-28T12:19:49.777Z","repository":{"id":252561061,"uuid":"840795829","full_name":"bstrdlord/failover","owner":"bstrdlord","description":"go library that allows you to add multiple urls and send a request to the active one (pool)","archived":false,"fork":false,"pushed_at":"2024-08-10T18:20:03.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-11T06:13:22.338Z","etag":null,"topics":["failover","failover-url","go","pool","url-pool"],"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/bstrdlord.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":"2024-08-10T17:54:00.000Z","updated_at":"2024-08-19T18:10:01.000Z","dependencies_parsed_at":"2024-08-10T19:08:39.825Z","dependency_job_id":null,"html_url":"https://github.com/bstrdlord/failover","commit_stats":null,"previous_names":["blockkwork/failover","bstrdlord/failover"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bstrdlord%2Ffailover","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bstrdlord%2Ffailover/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bstrdlord%2Ffailover/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bstrdlord%2Ffailover/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bstrdlord","download_url":"https://codeload.github.com/bstrdlord/failover/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241150243,"owners_count":19918334,"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":["failover","failover-url","go","pool","url-pool"],"created_at":"2025-01-11T06:13:13.403Z","updated_at":"2025-02-28T12:19:49.743Z","avatar_url":"https://github.com/bstrdlord.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# failover\ngo library that allows you to add multiple urls and send a request to the active one\n\n\n## 💡 Info\n**How it works?** failover saves your url and checks for availability every n seconds. if the url is unavailable, it saves and checks to wait for availability.\n\n**Request function:** Request uses round robin algorithm to select the url\n\n## 🚀 Usage\n```go\n\nfunc main() {\n\tf := failover.New(checkConn,\n\t\tfailover.OptCheckUrlDelay(30),\n\t\tfailover.OptMaxAttempts(10),\n\t\tfailover.OptCheckUrlBeforeAdding(true),\n\t\tfailover.OptReqOnErr(failover.ReqOnErrRemoveAndReconnect),\n\t)\n\n\t// first way to add url\n\tf.AddUrl(f.MustParseURL(\"https://google.com\"))\n\tf.AddUrl(f.MustParseURL(\"https://fjxiofujosidfujs.com\"))\n\tf.AddUrl(f.MustParseURL(\"https://fbi.gov\"))\n\n\t// second way to add url\n\tf.AddUrls(f.MustParseURL(\"https://youtube.com\"), f.MustParseURL(\"https://spotify.com\"), f.MustParseURL(\"https://github.com\"))\n\n\tfmt.Println(f.Request(requestFunc))\n\tfmt.Println(f.Request(requestFunc, failover.OptReqOnErr(failover.ReqOnErrIgnore))) // local option (only in this function) to ignore error\n}\n\nfunc checkConn(url *url.URL) error {\n\tresp, err := http.Get(url.String())\n\tif err != nil {\n\t\treturn err\n\t}\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn fmt.Errorf(\"unexpected status code: %d\", resp.StatusCode)\n\t}\n\treturn nil\n}\n\nfunc requestFunc(url *url.URL) error {\n\tfmt.Println(\"Request:\", url.String())\n\t_, err := http.Get(url.String())\n\tif err != nil {\n\t\treturn err\n\t}\n\treturn nil\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbstrdlord%2Ffailover","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbstrdlord%2Ffailover","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbstrdlord%2Ffailover/lists"}