Skip to content

kunalmemane/AreaCalculator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub go.mod Go version license GitHub Repo stars GitHub Issues or Pull Requests

Area Calculator

The Area Calculator API provides a simple and efficient way to compute the area of various geometric shapes, including square, circles, rectangles, triangles, and more.

credits: shutterstock.com

Table of Contents

Features

  • Calculate the area of common shapes: Circle, Rectangle, Triangle, and Square.
  • Fast and efficient calculations.
  • Formatted response
  • Efficient error handling

Prerequisite

Before you begin, ensure you have met the following requirements:

  • Go: You need to have Go v1.21+ installed on your machine. Download it from the official Go website.

    To check if Go is installed, run:

    go version

Installation

To get started with the Area Calculator, follow these steps:

  1. Clone the repository:

    git clone https://github.com/kunalmemane/AreaCalculator.git
    cd AreaCalculator
  2. Build the application:

    go build -o ./bin/main ./cmd/main.go
  3. Run the application:

    ./bin/main

The API will be available at http://localhost:8080/

Supported Shapes

  • Circle: Requires the radius.
  • Rectangle: Requires the length and breadth.
  • Triangle: Requires the sideA, sideB and sideC.
  • Square: Requires the side length.

Usage

Once the Application is running, you can make HTTP requests to calculate areas of supported shapes using the /getArea endpoint.

Endpoint

POST /getArea

Example Request

To calculate the area of multiple shapes, use the following curl command:

  • Triangle

    curl -X POST http://localhost:8080/getArea -d '{
            "shape":"Triangle",
            "sideB":20,
            "sideA": 10,
            "sideC":15    
        }' -H "Content-Type: application/json"

Test

  • To test the application run below commands

        make test
    
        or
    
        go test ./...

Makefile

This project includes a Makefile to simplify common tasks. You can use the following commands:

Available Commands

  • make build: Compile the project.
  • make run: Build and run the application.
  • make test: Run the tests for the project.
  • make clean: Remove build artifacts.
  • make all: To do clean, test, build, run tasks in one command.
  • make podman-build: Build Application Image using Podman.
  • make podman-run: Run Application Container Image.
  • make podman-push: Push Application Image to quay.io - podman login required.
  • make oc-deploy: Deploy application to openshift using docker strategy - oc login required.
  • make oc-delete: Delete all resources in openshift project - oc login required.

Contribute

Contributions are welcome! Please feel free to submit a Pull Request or open an Issue for discussion.

  1. Fork the repository.
  2. Create your feature branch (git checkout -b feature/AmazingFeature).
  3. Commit your changes (git commit -m 'Add some AmazingFeature').
  4. Push to the branch (git push origin feature/AmazingFeature).
  5. Open a Pull Request.

License

This project is licensed under the MIT License. See the LICENSE file for details.