Welcome to the Function Calling Utilities library, a Go library designed for ease of use with function calls. This library leverages Go 1.18+ generics to provide a simple yet powerful way to handle function invocations. It includes features such as Go2-like error handling and context invocation, making it an essential tool for modern Go developers.
- Generics Support: Utilize the power of Go's generics to create reusable functions.
- Error Handling: Implement Go2-like error handling to manage errors more effectively.
- Context Invocation: Call functions with context support to handle cancellations and timeouts.
- Lightweight: The library is designed to be simple and efficient, ensuring minimal overhead.
To install the library, use the following command:
go get github.com/om308185/fo
Here’s a quick overview of how to use the Function Calling Utilities library in your Go projects.
package main
import (
"context"
"fmt"
"github.com/om308185/fo"
)
func main() {
ctx := context.Background()
result, err := fo.Invoke(ctx, myFunction, "Hello, World!")
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Result:", result)
}
func myFunction(input string) (string, error) {
return input, nil
}
You can also use the library to handle more complex scenarios, such as passing multiple arguments and managing timeouts.
package main
import (
"context"
"fmt"
"time"
"github.com/om308185/fo"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
result, err := fo.Invoke(ctx, myAdvancedFunction, "Hello", "Go!")
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Result:", result)
}
func myAdvancedFunction(a, b string) (string, error) {
return fmt.Sprintf("%s %s", a, b), nil
}
For more examples, check the examples directory in the repository. You can find various use cases demonstrating the library's capabilities.
We welcome contributions to enhance the library. To contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeature
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/YourFeature
). - Create a pull request.
Please ensure your code adheres to the existing style and includes tests where applicable.
This project is licensed under the MIT License. See the LICENSE file for details.
To download the latest release, visit Releases. Here you can find the binaries and source code for the latest version. Make sure to download the appropriate files for your system and follow the instructions to execute them.
For detailed release notes and version history, refer to the Releases section.
The Function Calling Utilities library offers a robust solution for handling function calls in Go. Its use of generics, context support, and improved error handling makes it a valuable addition to any Go project.
Feel free to explore the repository and utilize the features it provides. If you have any questions or need further assistance, don't hesitate to reach out.
Happy coding!