This repository contains a collection of useful Go tools and utility packages designed to be easily integrated into your projects.
To use any tool from this repository, you'll need to import it into your Go project and then run go mod tidy
.
The stoper
package provides a simple way to handle graceful application shutdown upon receiving OS signals like Ctrl+C
(SIGINT) or SIGTERM
. It ensures your application can perform clean-up actions before exiting.
To include stoper
in your project, simply import it:
import (
"fmt"
// ... other imports
"github.com/cooler-SAI/go-Tools/stoper" // Import the stoper package
)
The zerolog
package provides a fast and flexible logger that produces structured (JSON by default) and leveled logs. It's designed for high performance and offers a simple API for rich logging capabilities.
To include zerolog
in your project, you'll first need to get the package:
import (
"fmt"
// ... other imports
"github.com/cooler-SAI/go-Tools/zerolog" // Import the zerolog package
)
This repository now includes a Dockerfile
located in the docker/
directory. This Dockerfile provides a standardized way to build a minimal and secure Docker image for Go applications that might utilize the tools from this repository.
- Multi-stage Builds: Utilizes a builder stage for compilation and a separate, minimal runtime stage (
alpine
based) to keep the final image size small. - Security Focused: Creates a non-root user (
appuser
) to run the application, enhancing security. - Optimized for Go:
- Disables CGO by default (
CGO_ENABLED=0
) for static binaries. - Targets Linux (
GOOS=linux
). - Strips debugging symbols (
-ldflags="-s -w"
) to reduce binary size.
- Disables CGO by default (
- Dependency Caching: Leverages Docker's layer caching for Go module dependencies to speed up subsequent builds.
- Configurable: Designed to build a Go project located in the parent directory relative to the
docker/
directory (i.e., your main Go project should be one level up from where theDockerfile
resides).
To build a Docker image for your Go project using this Dockerfile:
- Ensure your Go project is structured such that the
docker/
directory (containing theDockerfile
) is a subdirectory of your main project. - Navigate to the
docker/
directory in your terminal. - Run the Docker build command or use config in your IDE
Utility functions for generating random values using math/rand/v2.
To include random
in your project, you'll first need to get the package:
import (
"fmt"
// ... other imports
"github.com/cooler-SAI/go-Tools/random" // Import the zerolog package
)
To use any tool from this repository, you'll need to import it into your Go project and then run go mod tidy
.
// Returns random int in [min, max] range
num := random.RandRange(1, 100)