Loading documentation...
Loading documentation...
Loading documentation...
This guide will help you install and set up Ion in your Go project.
Before installing Ion, ensure you have:
go mod init if needed)Use go get to install Ion:
go get github.com/kolosys/ion@latestThis will download the package and add it to your go.mod file.
Ion is organized into separate packages. Import only the packages you need:
import (
"github.com/kolosys/ion/circuit" // Circuit breakers
"github.com/kolosys/ion/ratelimit" // Rate limiting
"github.com/kolosys/ion/semaphore" // Semaphores
"github.com/kolosys/ion/workerpool" // Worker pools
"github.com/kolosys/ion/observe" // Observability
)Create a simple test file to verify the installation:
package main
import (
"context"
"fmt"
"time"
"github.com/kolosys/ion/circuit"
)
func main() {
// Create a simple circuit breaker
cb := circuit.New("test-service",
circuit.WithFailureThreshold(5),
circuit.WithRecoveryTimeout(30*time.Second),
)
// Execute a simple operation
ctx := context.Background()
result, err := cb.Execute(ctx, func(ctx context.Context) (any, error) {
return "success", nil
})
if err != nil {
fmt.Printf("Error: %v
", err)
} else {
fmt.Printf("Result: %v
", result)
fmt.Println("Ion installed successfully!")
}
}Run the test:
go run main.goYou should see: Result: success and Ion installed successfully!
import "github.com/kolosys/ion/circuit"
cb := circuit.New("payment-service",
circuit.WithFailureThreshold(5),
circuit.WithRecoveryTimeout(30*time.Second),
)import "github.com/kolosys/ion/ratelimit"
limiter := ratelimit.NewTokenBucket(
ratelimit.PerSecond(10), // 10 requests per second
20, // burst capacity of 20
)import "github.com/kolosys/ion/semaphore"
sem := semaphore.NewWeighted(10, // capacity of 10
semaphore.WithName("db-pool"),
semaphore.WithFairness(semaphore.FIFO),
)import "github.com/kolosys/ion/workerpool"
pool := workerpool.New(4, 20, // 4 workers, queue size 20
workerpool.WithName("image-processor"),
)import "github.com/kolosys/ion/observe"
obs := observe.New().
WithLogger(myLogger).
WithMetrics(myMetrics).
WithTracer(myTracer)To update to the latest version:
go get -u github.com/kolosys/ionTo update to a specific version:
go get github.com/kolosys/ion@latestCheck available versions on the GitHub releases page.
To install a specific version of the package:
go get github.com/kolosys/ion@latestIf you want to contribute or modify the library:
git clone https://github.com/kolosys/ion.git
cd ionIon has zero external dependencies, so no additional packages are required:
go mod downloadgo test ./...Run tests with race detection:
go test -race ./...go test -bench=. -benchmem ./...If you encounter a "module not found" error:
GOPATH is set correctlygo version (requires 1.21+)go clean -modcache and reinstall:go clean -modcache
go get github.com/kolosys/ion@latestFor private repositories, configure Git to use SSH or a personal access token:
git config --global url."git@github.com:".insteadOf "https://github.com/"Or set up GOPRIVATE:
export GOPRIVATE=github.com/kolosys/ionIf you encounter version conflicts with other packages:
go.mod file for version constraintsgo mod tidy to resolve dependencies:go mod tidygo list -m -versions github.com/kolosys/ionIon works seamlessly with VS Code's Go extension. Ensure you have:
gopls installed and up to date:go install golang.org/x/tools/gopls@latestIon is fully supported in GoLand. The IDE will automatically:
For Vim/Neovim users, ensure you have:
gopls installed for LSP supportvim-lsp, coc.nvim)Now that you have Ion installed, check out the Quick Start Guide to learn how to use it in your projects.
This guide will help you install and set up Ion in your Go project.
Before installing Ion, ensure you have:
go mod init if needed)Use go get to install Ion:
go get github.com/kolosys/ion@latestThis will download the package and add it to your go.mod file.
Ion is organized into separate packages. Import only the packages you need:
import (
"github.com/kolosys/ion/circuit" // Circuit breakers
"github.com/kolosys/ion/ratelimit" // Rate limiting
"github.com/kolosys/ion/semaphore" // Semaphores
"github.com/kolosys/ion/workerpool" // Worker pools
"github.com/kolosys/ion/observe" // Observability
)Create a simple test file to verify the installation:
package main
import (
"context"
"fmt"
"time"
"github.com/kolosys/ion/circuit"
)
func main() {
// Create a simple circuit breaker
cb := circuit.New("test-service",
circuit.WithFailureThreshold(5),
circuit.WithRecoveryTimeout(30*time.Second),
)
// Execute a simple operation
ctx := context.Background()
result, err := cb.Execute(ctx, func(ctx context.Context) (any, error) {
return "success", nil
})
if err != nil {
fmt.Printf("Error: %v
", err)
} else {
fmt.Printf("Result: %v
", result)
fmt.Println("Ion installed successfully!")
}
}Run the test:
go run main.goYou should see: Result: success and Ion installed successfully!
import "github.com/kolosys/ion/circuit"
cb := circuit.New("payment-service",
circuit.WithFailureThreshold(5),
circuit.WithRecoveryTimeout(30*time.Second),
)import "github.com/kolosys/ion/ratelimit"
limiter := ratelimit.NewTokenBucket(
ratelimit.PerSecond(10), // 10 requests per second
20, // burst capacity of 20
)import "github.com/kolosys/ion/semaphore"
sem := semaphore.NewWeighted(10, // capacity of 10
semaphore.WithName("db-pool"),
semaphore.WithFairness(semaphore.FIFO),
)import "github.com/kolosys/ion/workerpool"
pool := workerpool.New(4, 20, // 4 workers, queue size 20
workerpool.WithName("image-processor"),
)import "github.com/kolosys/ion/observe"
obs := observe.New().
WithLogger(myLogger).
WithMetrics(myMetrics).
WithTracer(myTracer)To update to the latest version:
go get -u github.com/kolosys/ionTo update to a specific version:
go get github.com/kolosys/ion@latestCheck available versions on the GitHub releases page.
To install a specific version of the package:
go get github.com/kolosys/ion@latestIf you want to contribute or modify the library:
git clone https://github.com/kolosys/ion.git
cd ionIon has zero external dependencies, so no additional packages are required:
go mod downloadgo test ./...Run tests with race detection:
go test -race ./...go test -bench=. -benchmem ./...If you encounter a "module not found" error:
GOPATH is set correctlygo version (requires 1.21+)go clean -modcache and reinstall:go clean -modcache
go get github.com/kolosys/ion@latestFor private repositories, configure Git to use SSH or a personal access token:
git config --global url."git@github.com:".insteadOf "https://github.com/"Or set up GOPRIVATE:
export GOPRIVATE=github.com/kolosys/ionIf you encounter version conflicts with other packages:
go.mod file for version constraintsgo mod tidy to resolve dependencies:go mod tidygo list -m -versions github.com/kolosys/ionIon works seamlessly with VS Code's Go extension. Ensure you have:
gopls installed and up to date:go install golang.org/x/tools/gopls@latestIon is fully supported in GoLand. The IDE will automatically:
For Vim/Neovim users, ensure you have:
gopls installed for LSP supportvim-lsp, coc.nvim)Now that you have Ion installed, check out the Quick Start Guide to learn how to use it in your projects.
go get github.com/kolosys/ion@latestimport (
"github.com/kolosys/ion/circuit" // Circuit breakers
"github.com/kolosys/ion/ratelimit" // Rate limiting
"github.com/kolosys/ion/semaphore" // Semaphores
"github.com/kolosys/ion/workerpool" // Worker pools
"github.com/kolosys/ion/observe" // Observability
)package main
import (
"context"
"fmt"
"time"
"github.com/kolosys/ion/circuit"
)
func main() {
// Create a simple circuit breaker
cb := circuit.New("test-service",
circuit.WithFailureThreshold(5),
circuit.WithRecoveryTimeout(30*time.Second),
)
// Execute a simple operation
ctx := context.Background()
result, err := cb.Execute(ctx, func(ctx context.Context) (any, error) {
return "success", nil
})
if err != nil {
fmt.Printf("Error: %v
", err)
} else {
fmt.Printf("Result: %v
", result)
fmt.Println("Ion installed successfully!")
}
}go run main.goimport "github.com/kolosys/ion/circuit"
cb := circuit.New("payment-service",
circuit.WithFailureThreshold(5),
circuit.WithRecoveryTimeout(30*time.Second),
)import "github.com/kolosys/ion/ratelimit"
limiter := ratelimit.NewTokenBucket(
ratelimit.PerSecond(10), // 10 requests per second
20, // burst capacity of 20
)import "github.com/kolosys/ion/semaphore"
sem := semaphore.NewWeighted(10, // capacity of 10
semaphore.WithName("db-pool"),
semaphore.WithFairness(semaphore.FIFO),
)import "github.com/kolosys/ion/workerpool"
pool := workerpool.New(4, 20, // 4 workers, queue size 20
workerpool.WithName("image-processor"),
)import "github.com/kolosys/ion/observe"
obs := observe.New().
WithLogger(myLogger).
WithMetrics(myMetrics).
WithTracer(myTracer)go get -u github.com/kolosys/iongo get github.com/kolosys/ion@latestgo get github.com/kolosys/ion@latestgit clone https://github.com/kolosys/ion.git
cd iongo mod downloadgo test ./...go test -race ./...go test -bench=. -benchmem ./...go clean -modcache
go get github.com/kolosys/ion@latestgit config --global url."git@github.com:".insteadOf "https://github.com/"export GOPRIVATE=github.com/kolosys/iongo mod tidygo list -m -versions github.com/kolosys/iongo install golang.org/x/tools/gopls@latestgo get github.com/kolosys/ion@latestimport (
"github.com/kolosys/ion/circuit" // Circuit breakers
"github.com/kolosys/ion/ratelimit" // Rate limiting
"github.com/kolosys/ion/semaphore" // Semaphores
"github.com/kolosys/ion/workerpool" // Worker pools
"github.com/kolosys/ion/observe" // Observability
)package main
import (
"context"
"fmt"
"time"
"github.com/kolosys/ion/circuit"
)
func main() {
// Create a simple circuit breaker
cb := circuit.New("test-service",
circuit.WithFailureThreshold(5),
circuit.WithRecoveryTimeout(30*time.Second),
)
// Execute a simple operation
ctx := context.Background()
result, err := cb.Execute(ctx, func(ctx context.Context) (any, error) {
return "success", nil
})
if err != nil {
fmt.Printf("Error: %v
", err)
} else {
fmt.Printf("Result: %v
", result)
fmt.Println("Ion installed successfully!")
}
}go run main.goimport "github.com/kolosys/ion/circuit"
cb := circuit.New("payment-service",
circuit.WithFailureThreshold(5),
circuit.WithRecoveryTimeout(30*time.Second),
)import "github.com/kolosys/ion/ratelimit"
limiter := ratelimit.NewTokenBucket(
ratelimit.PerSecond(10), // 10 requests per second
20, // burst capacity of 20
)import "github.com/kolosys/ion/semaphore"
sem := semaphore.NewWeighted(10, // capacity of 10
semaphore.WithName("db-pool"),
semaphore.WithFairness(semaphore.FIFO),
)import "github.com/kolosys/ion/workerpool"
pool := workerpool.New(4, 20, // 4 workers, queue size 20
workerpool.WithName("image-processor"),
)import "github.com/kolosys/ion/observe"
obs := observe.New().
WithLogger(myLogger).
WithMetrics(myMetrics).
WithTracer(myTracer)go get -u github.com/kolosys/iongo get github.com/kolosys/ion@latestgo get github.com/kolosys/ion@latestgit clone https://github.com/kolosys/ion.git
cd iongo mod downloadgo test ./...go test -race ./...go test -bench=. -benchmem ./...go clean -modcache
go get github.com/kolosys/ion@latestgit config --global url."git@github.com:".insteadOf "https://github.com/"export GOPRIVATE=github.com/kolosys/iongo mod tidygo list -m -versions github.com/kolosys/iongo install golang.org/x/tools/gopls@latest