Simplify your decision-making logic with condigo, a lightweight Go library providing a fluent interface for conditional statements. Easily define complex logic flows in a readable, linear fashion.
Get a string object based on a single condition.
result := condigo.When(true).
Then("Success").
Else("Failure")
fmt.Println(result) // Output: Success
Handle multiple conditions with Then
, ElseIf
, and Else
.
result := condigo.When(false).
Then("First").
ElseIf(true, "Second").
Else("Default")
fmt.Println(result) // Output: Second
Execute functions based on conditions and retrieve their return values.
resultFunc, _ := condigo.When(true).
Then(func() bool {
fmt.Println("Inside Then")
return true
}).
Else(func() bool {
fmt.Println("Inside Else")
return false
}).(func() bool)
fmt.Println(resultFunc()) // Output: Inside Then, then true
Running the main.go
file in examples
folder provided in this repository will output:
Success
Second
Inside Then
true
- Issues & Features: Report bugs or suggest new features by opening an issue on this repository.
- Pull Requests: Contributions are welcome. Please submit a pull request for review.
- Contact: For direct support, you can try contacting the maintainer on Linkedin