Number Index Service is a web application written in Go that allows users to search for the index of a given numeric value in a sorted list of numbers. The application handles HTTP requests and returns the index of the found value or the closest value within a specified tolerance.
- Loading a sorted list of numbers from a text file.
- Searching for the index of a given numeric value.
- Returning the index of the closest value if the exact value is not found, within a defined tolerance level.
- Go (version 1.15 or later)
- A text file containing sorted numbers (named
input.txt
by default)
To run this project, the following external packages are required:
- Viper: A package used for loading application configurations. More information.
- Logrus: An advanced logging package for Go. More information.
- Testify: A package used for simplifying the writing of unit tests. More information.
You can install all required dependencies by running the following command:
go get -u github.com/spf13/viper github.com/sirupsen/logrus github.com/stretchr/testify
- To start the service, in the project folder run:
go run main.go
- The service will start on the default port (e.g., 8080). You can access the service at
http://localhost:8080
.
- Send a GET request to
/endpoint/[number]
where[number]
is the numeric value you want to search for. - The service will respond with the index of the number or the closest match within the tolerance.
You can configure the service by editing the config.yaml
file. Available configurations include:
server.port
: Port on which the service will run.logging.level
: Level of logging (e.g., Info, Debug, Error).
To run the unit tests, use the following command:
make test