From 18ec672f513e2854b14f01c22bd0988e994cc4ba Mon Sep 17 00:00:00 2001 From: Raj Nandan Sharma Date: Wed, 6 Mar 2024 10:37:27 +0530 Subject: [PATCH] updated readme --- README.md | 129 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 68 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 2e9cbba..95c0969 100644 --- a/README.md +++ b/README.md @@ -4,70 +4,12 @@ The `tripper` is a lightweight, 0 dependencies package that provides functionality for monitoring the status of a circuit. It allows you to track the success and failure counts of events and determine if a circuit should be open or closed based on configurable thresholds. This can be useful in scenarios where you want to implement circuit breaker patterns or manage the availability of services. -## Constants - -- `ThresholdCount` represents a threshold type based on count. -- `ThresholdPercentage` represents a threshold type based on percentage. - -## Types - -### Monitor - -The `Monitor` struct represents a monitoring entity that tracks the status of a circuit. It contains the following fields: - -- `Name`: Name of the monitor. -- `CircuitOpen`: Indicates whether the circuit is open or closed. -- `LastCapturedAt`: Timestamp of the last captured event. -- `CircuitOpenedSince`: Timestamp when the circuit was opened. -- `FailureCount`: Number of failures recorded. -- `SuccessCount`: Number of successes recorded. -- `Threshold`: Threshold value for triggering circuit open. -- `ThresholdType`: Type of threshold (e.g., percentage, count). -- `MinimumCount`: Minimum number of events required for monitoring. -- `IntervalInSeconds`: Interval in seconds for monitoring (should be non-zero and a multiple of 60). - -## Functions - -### AddMonitor +### Installation -```go -func AddMonitor(monitor Monitor) error +```bash +go get github.com/rajnandan1/go-tripper ``` -`AddMonitor` adds a new monitor to the circuits map. It checks if a monitor with the given name already exists. It also validates the threshold type and threshold value. If the minimum count or interval is invalid, it returns an error. If the interval is not a multiple of 60, it returns an error. - -### UpdateMonitorStatusByName - -```go -func UpdateMonitorStatusByName(name string, success bool) (*Monitor, error) -``` - -`UpdateMonitorStatusByName` updates the status of a monitor by its name. It takes the name of the monitor and a boolean indicating the success status. It returns the updated monitor and an error, if any. - -### IsCircuitOpen - -```go -func IsCircuitOpen(name string) (bool, error) -``` - -`IsCircuitOpen` checks if a circuit with the given name is open or closed. It returns a boolean indicating whether the circuit is open or closed, and an error if the circuit does not exist. - -### GetMonitorByName - -```go -func GetMonitorByName(name string) (*Monitor, error) -``` - -`GetMonitorByName` retrieves a monitor by its name. It returns the monitor if found, otherwise it returns an error. - -### GetAllMonitors - -```go -func GetAllMonitors() map[string]*Monitor -``` - -`GetAllMonitors` returns a map of all monitors. - ## How to Use 1. Import the `tripper` package into your Go code: @@ -139,3 +81,68 @@ for name, monitor := range monitors { // Process each monitor } ``` + + +## Constants + +- `ThresholdCount` represents a threshold type based on count. +- `ThresholdPercentage` represents a threshold type based on percentage. + +## Types + +### Monitor + +The `Monitor` struct represents a monitoring entity that tracks the status of a circuit. It contains the following fields: + +- `Name`: Name of the monitor. +- `CircuitOpen`: Indicates whether the circuit is open or closed. +- `LastCapturedAt`: Timestamp of the last captured event. +- `CircuitOpenedSince`: Timestamp when the circuit was opened. +- `FailureCount`: Number of failures recorded. +- `SuccessCount`: Number of successes recorded. +- `Threshold`: Threshold value for triggering circuit open. +- `ThresholdType`: Type of threshold (e.g., percentage, count). +- `MinimumCount`: Minimum number of events required for monitoring. +- `IntervalInSeconds`: Interval in seconds for monitoring (should be non-zero and a multiple of 60). + +## Functions + +### AddMonitor + +```go +func AddMonitor(monitor Monitor) error +``` + +`AddMonitor` adds a new monitor to the circuits map. It checks if a monitor with the given name already exists. It also validates the threshold type and threshold value. If the minimum count or interval is invalid, it returns an error. If the interval is not a multiple of 60, it returns an error. + +### UpdateMonitorStatusByName + +```go +func UpdateMonitorStatusByName(name string, success bool) (*Monitor, error) +``` + +`UpdateMonitorStatusByName` updates the status of a monitor by its name. It takes the name of the monitor and a boolean indicating the success status. It returns the updated monitor and an error, if any. + +### IsCircuitOpen + +```go +func IsCircuitOpen(name string) (bool, error) +``` + +`IsCircuitOpen` checks if a circuit with the given name is open or closed. It returns a boolean indicating whether the circuit is open or closed, and an error if the circuit does not exist. + +### GetMonitorByName + +```go +func GetMonitorByName(name string) (*Monitor, error) +``` + +`GetMonitorByName` retrieves a monitor by its name. It returns the monitor if found, otherwise it returns an error. + +### GetAllMonitors + +```go +func GetAllMonitors() map[string]*Monitor +``` + +`GetAllMonitors` returns a map of all monitors.