{"id":13543156,"url":"https://github.com/afex/hystrix-go","last_synced_at":"2025-05-12T15:29:14.561Z","repository":{"id":12530484,"uuid":"15200429","full_name":"afex/hystrix-go","owner":"afex","description":"Netflix's Hystrix latency and fault tolerance library, for Go ","archived":false,"fork":false,"pushed_at":"2024-02-24T18:44:10.000Z","size":265,"stargazers_count":4303,"open_issues_count":56,"forks_count":479,"subscribers_count":91,"default_branch":"master","last_synced_at":"2025-05-03T03:40:42.503Z","etag":null,"topics":[],"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/afex.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":"2013-12-15T08:51:23.000Z","updated_at":"2025-04-29T05:57:45.000Z","dependencies_parsed_at":"2024-06-18T10:52:11.287Z","dependency_job_id":"7b324f39-6c94-437a-8d70-7550a0271ced","html_url":"https://github.com/afex/hystrix-go","commit_stats":{"total_commits":234,"total_committers":19,"mean_commits":12.31578947368421,"dds":0.4658119658119658,"last_synced_commit":"fa1af6a1f4f56e0e50d427fe901cd604d8c6fb8a"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afex%2Fhystrix-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afex%2Fhystrix-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afex%2Fhystrix-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afex%2Fhystrix-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afex","download_url":"https://codeload.github.com/afex/hystrix-go/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253765445,"owners_count":21960730,"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":[],"created_at":"2024-08-01T11:00:24.428Z","updated_at":"2025-05-12T15:29:14.511Z","avatar_url":"https://github.com/afex.png","language":"Go","funding_links":[],"categories":["Utilities","Utility","Go","HarmonyOS","公用事业公司","工具库","实用工具","工具库`可以提升效率的通用代码库和工具`"],"sub_categories":["Utility/Miscellaneous","HTTP Clients","Windows Manager","实用程序/Miscellaneous","Advanced Console UIs","Fail injection","交流","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","查询语"],"readme":"hystrix-go\n==========\n\n[![Build Status](https://travis-ci.org/afex/hystrix-go.png?branch=master)](https://travis-ci.org/afex/hystrix-go)\n[![GoDoc Documentation](http://godoc.org/github.com/afex/hystrix-go/hystrix?status.png)](https://godoc.org/github.com/afex/hystrix-go/hystrix)\n\n[Hystrix](https://github.com/Netflix/Hystrix) is a great project from Netflix.\n\n\u003e Hystrix is a latency and fault tolerance library designed to isolate points of access to remote systems, services and 3rd party libraries, stop cascading failure and enable resilience in complex distributed systems where failure is inevitable.\n\nI think the Hystrix patterns of programmer-defined fallbacks and adaptive health monitoring are good for any distributed system. Go routines and channels are great concurrency primitives, but don't directly help our application stay available during failures.\n\nhystrix-go aims to allow Go programmers to easily build applications with similar execution semantics of the Java-based Hystrix library.\n\nFor more about how Hystrix works, refer to the [Java Hystrix wiki](https://github.com/Netflix/Hystrix/wiki)\n\nFor API documentation, refer to [GoDoc](https://godoc.org/github.com/afex/hystrix-go/hystrix)\n\nHow to use\n----------\n\n```go\nimport \"github.com/afex/hystrix-go/hystrix\"\n```\n\n### Execute code as a Hystrix command\n\nDefine your application logic which relies on external systems, passing your function to ```hystrix.Go```. When that system is healthy this will be the only thing which executes.\n\n```go\nhystrix.Go(\"my_command\", func() error {\n\t// talk to other services\n\treturn nil\n}, nil)\n```\n\n### Defining fallback behavior\n\nIf you want code to execute during a service outage, pass in a second function to ```hystrix.Go```. Ideally, the logic here will allow your application to gracefully handle external services being unavailable.\n\nThis triggers when your code returns an error, or whenever it is unable to complete based on a [variety of health checks](https://github.com/Netflix/Hystrix/wiki/How-it-Works).\n\n```go\nhystrix.Go(\"my_command\", func() error {\n\t// talk to other services\n\treturn nil\n}, func(err error) error {\n\t// do this when services are down\n\treturn nil\n})\n```\n\n### Waiting for output\n\nCalling ```hystrix.Go``` is like launching a goroutine, except you receive a channel of errors you can choose to monitor.\n\n```go\noutput := make(chan bool, 1)\nerrors := hystrix.Go(\"my_command\", func() error {\n\t// talk to other services\n\toutput \u003c- true\n\treturn nil\n}, nil)\n\nselect {\ncase out := \u003c-output:\n\t// success\ncase err := \u003c-errors:\n\t// failure\n}\n```\n\n### Synchronous API\n\nSince calling a command and immediately waiting for it to finish is a common pattern, a synchronous API is available with the `hystrix.Do` function which returns a single error.\n\n```go\nerr := hystrix.Do(\"my_command\", func() error {\n\t// talk to other services\n\treturn nil\n}, nil)\n```\n\n### Configure settings\n\nDuring application boot, you can call ```hystrix.ConfigureCommand()``` to tweak the settings for each command.\n\n```go\nhystrix.ConfigureCommand(\"my_command\", hystrix.CommandConfig{\n\tTimeout:               1000,\n\tMaxConcurrentRequests: 100,\n\tErrorPercentThreshold: 25,\n})\n```\n\nYou can also use ```hystrix.Configure()``` which accepts a ```map[string]CommandConfig```.\n\n### Enable dashboard metrics\n\nIn your main.go, register the event stream HTTP handler on a port and launch it in a goroutine.  Once you configure turbine for your [Hystrix Dashboard](https://github.com/Netflix/Hystrix/tree/master/hystrix-dashboard) to start streaming events, your commands will automatically begin appearing.\n\n```go\nhystrixStreamHandler := hystrix.NewStreamHandler()\nhystrixStreamHandler.Start()\ngo http.ListenAndServe(net.JoinHostPort(\"\", \"81\"), hystrixStreamHandler)\n```\n\n### Send circuit metrics to Statsd\n\n```go\nc, err := plugins.InitializeStatsdCollector(\u0026plugins.StatsdCollectorConfig{\n\tStatsdAddr: \"localhost:8125\",\n\tPrefix:     \"myapp.hystrix\",\n})\nif err != nil {\n\tlog.Fatalf(\"could not initialize statsd client: %v\", err)\n}\n\nmetricCollector.Registry.Register(c.NewStatsdCollector)\n```\n\nFAQ\n---\n\n**What happens if my run function panics? Does hystrix-go trigger the fallback?**\n\nNo. hystrix-go does not use ```recover()``` so panics will kill the process like normal.\n\nBuild and Test\n--------------\n\n- Install vagrant and VirtualBox\n- Clone the hystrix-go repository\n- Inside the hystrix-go directory, run ```vagrant up```, then ```vagrant ssh```\n- ```cd /go/src/github.com/afex/hystrix-go```\n- ```go test ./...```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafex%2Fhystrix-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafex%2Fhystrix-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafex%2Fhystrix-go/lists"}