{"id":17256728,"url":"https://github.com/rajnandan1/go-tripper","last_synced_at":"2025-07-30T00:33:47.029Z","repository":{"id":226138574,"uuid":"767851660","full_name":"rajnandan1/go-tripper","owner":"rajnandan1","description":"The Go Tripper package provides functionality for monitoring the status of a circuit. Track success and failure counts, implement circuit breaker patterns, and manage service availability.","archived":false,"fork":false,"pushed_at":"2024-04-21T18:07:02.000Z","size":39,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-19T09:25:56.303Z","etag":null,"topics":["circuit-breaker","go","golang"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/rajnandan1/go-tripper","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/rajnandan1.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":"2024-03-06T02:21:06.000Z","updated_at":"2025-01-28T15:06:19.000Z","dependencies_parsed_at":"2024-06-21T13:03:31.336Z","dependency_job_id":"d5cda9f1-fe67-4f3e-a48e-ba0267bf7fbc","html_url":"https://github.com/rajnandan1/go-tripper","commit_stats":null,"previous_names":["rajnandan1/go-tripper"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/rajnandan1/go-tripper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajnandan1%2Fgo-tripper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajnandan1%2Fgo-tripper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajnandan1%2Fgo-tripper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajnandan1%2Fgo-tripper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rajnandan1","download_url":"https://codeload.github.com/rajnandan1/go-tripper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rajnandan1%2Fgo-tripper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267785823,"owners_count":24144122,"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-07-29T02:00:12.549Z","response_time":2574,"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":["circuit-breaker","go","golang"],"created_at":"2024-10-15T07:15:18.866Z","updated_at":"2025-07-30T00:33:47.004Z","avatar_url":"https://github.com/rajnandan1.png","language":"Go","funding_links":[],"categories":["Utilities","Recently Updated","公用事业公司"],"sub_categories":["Utility/Miscellaneous","[Nov 16, 2024](/content/2024/11/16/README.md)","实用程序/Miscellaneous"],"readme":" \n# Tripper\n\nTripper is a circuit breaker package for Go that allows you to circuit and control the status of circuits.\n\n![Tripper](https://github.com/rajnandan1/go-tripper/assets/16224367/ba0b329c-6aa7-4d5f-aa35-4f7d28e9e3bf)\n\n[![Coverage Status](https://coveralls.io/repos/github/rajnandan1/go-tripper/badge.svg?branch=main)](https://coveralls.io/github/rajnandan1/go-tripper?branch=main) [![Go Reference](https://pkg.go.dev/badge/github.com/rajnandan1/go-tripper.svg)](https://pkg.go.dev/github.com/rajnandan1/go-tripper)\n\n## Installation\n\nTo install Tripper, use `go get`:\n\n```shell\ngo get github.com/rajnandan1/go-tripper\n```\n\n## Usage\n\nImport the Tripper package in your Go code:\n\n```go\nimport \"github.com/rajnandan1/go-tripper\"\n```\n\n\n\n### Adding a Circuit\n\nTo add a circuit to the Tripper, use the `ConfigureCircuit` function:\n\n#### Circuit With Count\n\n```go\n//Adding a circuit that will trip the circuit if count of failure is more than 10 in 1 minute\n//for a minimum of 100 count\ncircuitOptions := tripper.CircuitOptions{\n    Name:              \"example-circuit\",\n    Threshold:         10,\n    ThresholdType:     tripper.ThresholdCount,\n    MinimumCount:      100,\n    IntervalInSeconds: 60,\n    OnCircuitOpen:     onCircuitOpenCallback,\n    OnCircuitClosed:   onCircuitClosedCallback,\n}\n\ncircuit, err := tripper.ConfigureCircuit(circuitOptions)\nif err != nil {\n    fmt.Println(\"Failed to add circuit:\", err)\n    return\n}\n```\n\n#### Circuit With Percentage\n```go\n//Adding a circuit that will trip the circuit if count of failure is more than 10% in 1 minute\n//for a minimum of 100 count\ncircuitOptions := tripper.CircuitOptions{\n    Name:              \"example-circuit\",\n    Threshold:         10,\n    ThresholdType:     tripper.ThresholdPercentage,\n    MinimumCount:      100,\n    IntervalInSeconds: 60,\n    OnCircuitOpen:     onCircuitOpenCallback,\n    OnCircuitClosed:   onCircuitClosedCallback,\n}\n\ncircuit, err := tripper.ConfigureCircuit(circuitOptions)\nif err != nil {\n    fmt.Println(\"Failed to add circuit:\", err)\n    return\n}\n```\n\n#### Circuit With Consecutive Errors\n```go\n//Adding a circuit that will trip the circuit if 10 consecutive erros occur in 1 minute\n//for a minimum of 100 count\ncircuitOptions := tripper.CircuitOptions{\n    Name:              \"example-circuit\",\n    Threshold:         10,\n    ThresholdType:     tripper.ThresholdConsecutive,\n    MinimumCount:      100,\n    IntervalInSeconds: 60,\n    OnCircuitOpen:     onCircuitOpenCallback,\n    OnCircuitClosed:   onCircuitClosedCallback,\n}\n\ncircuit, err := tripper.ConfigureCircuit(circuitOptions)\nif err != nil {\n    fmt.Println(\"Failed to add circuit:\", err)\n    return\n}\n```\n\n#### Circuit with Callbacks\n```go\nfunc onCircuitOpenCallback(x tripper.CallbackEvent){\n    fmt.Println(\"Callback OPEN\")\n\tfmt.Println(x.FailureCount)\n\tfmt.Println(x.SuccessCount)\n\tfmt.Println(x.Timestamp)\n}\nfunc onCircuitClosedCallback(x tripper.CallbackEvent){\n    fmt.Println(\"Callback Closed\")\n\tfmt.Println(x.FailureCount)\n\tfmt.Println(x.SuccessCount)\n\tfmt.Println(x.Timestamp)\n}\ncircuitOptions := tripper.CircuitOptions{\n    Name:              \"example-circuit\",\n    Threshold:         10,\n    ThresholdType:     tripper.ThresholdCount,\n    MinimumCount:      100,\n    IntervalInSeconds: 60,\n    OnCircuitOpen:     onCircuitOpenCallback,\n    OnCircuitClosed:   onCircuitClosedCallback,\n}\n\ncircuit, err := tripper.ConfigureCircuit(circuitOptions)\nif err != nil {\n    fmt.Println(\"Failed to add circuit:\", err)\n    return\n}\n```\n### Circuit Options\n\n| Option              | Description                                                  | Required | Type       |\n|---------------------|--------------------------------------------------------------|----------|------------|\n| `Name`              | The name of the circuit.                                     | Required | `string`   |\n| `Threshold`         | The threshold value for the circuit.                          | Required | `float32` |\n| `ThresholdType`     | The type of threshold (`ThresholdCount` or `ThresholdPercentage`or `ThresholdConsecutive`). | Required | `string`  |\n| `MinimumCount`      | The minimum number of events required for monitoring.         | Required | `int64`   |\n| `IntervalInSeconds` | The time interval for monitoring in seconds.                  | Required | `int`     |\n| `OnCircuitOpen`     | Callback function called when the circuit opens.              | Optional | `func()`  |\n| `OnCircuitClosed`   | Callback function called when the circuit closes.             | Optional | `func()`  |\n\nCircuits are reset after `IntervalInSeconds`\n\n### Updating Circuit Status\n\nTo update the status of a circuit based on the success of an event, use the `UpdateStatus` function:\n\n```go\ncircuit.UpdateStatus(true)  // Success event\ncircuit.UpdateStatus(false) // Failure event\n```\n\n### Checking Circuit Status\n\nTo check if a circuit is open or closed, use the `IsCircuitOpen` function:\n\n```go\nisOpen := circuit.IsCircuitOpen()\nif isOpen {\n    fmt.Println(\"Circuit is open\")\n} else {\n    fmt.Println(\"Circuit is closed\")\n}\n```\n \n\n### Example: HTTP Request with Circuit Breaker\n\nHere's an example of using Tripper to handle HTTP requests with a circuit breaker:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"time\"\n\n    \"github.com/rajnandan1/go-tripper\"\n)\n\nfunc main() {\n    // Configure the circuit options\n    circuitOptions := tripper.CircuitOptions{\n        Name:              \"MyServiceMonitor\",\n        Threshold:         50, // Threshold for triggering circuit open (percentage)\n        ThresholdType:     tripper.ThresholdPercentage,\n        MinimumCount:      10,  // Minimum number of events required for monitoring\n        IntervalInSeconds: 60,  // Interval in seconds for monitoring\n        OnCircuitOpen: func(event tripper.CallbackEvent) {\n            fmt.Println(\"Circuit opened:\", event)\n        },\n        OnCircuitClosed: func(event tripper.CallbackEvent) {\n            fmt.Println(\"Circuit closed:\", event)\n        },\n    }\n\n    // Create a new circuit\n    circuit, err := tripper.ConfigureCircuit(circuitOptions)\n    if err != nil {\n        fmt.Println(\"Error creating circuit:\", err)\n        return\n    }\n\n    // Simulate calling a service\n    for i := 0; i \u003c 20; i++ {\n        success := i%2 == 0 // Simulate failures every other call\n        circuit.UpdateStatus(success)\n        time.Sleep(time.Second)\n    }\n\n    // Check if the circuit is open\n    if circuit.IsCircuitOpen() {\n        fmt.Println(\"Circuit is open!\")\n    } else {\n        fmt.Println(\"Circuit is closed.\")\n    }\n}\n```\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajnandan1%2Fgo-tripper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frajnandan1%2Fgo-tripper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frajnandan1%2Fgo-tripper/lists"}