A simple HTTP server for calculating averages, sums, and counts of numbers (even, odd, or all) with a RESTful API.
First, ensure you have Go installed. Version 1.22.7
or higher is required.
Use the following command to clone and install the project:
git clone https://github.com/Martande8055/go-redhat.git
cd go-redhat/
go mod tidy
go build -o main main.go
To run the server:
./main
The server will start on port 3100.
Usage You can send POST requests to the following endpoints to calculate averages:
-
For Even Numbers:
/even
-
For Odd Numbers:
/odd
-
For All Numbers:
/evenodd
Example Request Here's how to make a request using curl:
curl -X POST http://localhost:3100/even -H "Content-Type: application/json" -d '{"op": "avg", "nums": [2, 4, 6, 8]}'
Calculate the average, sum, or count of even numbers.
You can Specify different Operations as follows:
-
avg
for average -
sum
for sum -
count
for count
Json Input Example:
{
"op": "avg",
"nums": [2, 4, 6, 8]
}
Run the unit tests with:
go test ./... -v
To run the application in a Docker container:
- Build the image:
podman build -t go_average_app .
- Run the container:
podman run -p 3100:3100 go_average_app
If you find this project helpful, please give it a star on GitHub!
The Average Calculation API is free and open-source software licensed under the MIT License.