obkio-test

module
v0.0.0-...-6128624 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2025 License: MIT

README ยถ

Agents Monitoring API

Overview

The Agents Monitoring API is a Go-based REST API that allows agents to send their IP addresses, retrieve IP-related details (such as ASN and ISP), and manage agent information. The API uses SQLite for storage and integrates with an external IP lookup service (ip-api.com).


Features

  • Accepts IP address submissions from agents.
  • Retrieves and stores Autonomous System Number (ASN) and Internet Service Provider (ISP) details.
  • Provides endpoints to list all agents and fetch details of a specific agent.
  • Supports Docker and .env configuration.

API Endpoints

Method Endpoint Description
POST /agents Register an agent's IP address
GET /agents Get a list of all registered agents
GET /agents/{id} Get details (ASN, ISP) of a specific agent
๐Ÿ”น Example: Register an Agent
Request:
curl -X POST "http://localhost:8080/agents" \
     -H "Content-Type: application/json" \
     -d '{"ip_address": "8.8.8.8"}'

๐Ÿ”น Example: Get a List of Agents
Request:
curl -X GET "http://localhost:8080/agents"
Response:
[
  {
    "id": 1,
    "ip_address": "8.8.8.8",
},
  {
    "id": 2,
    "ip_address": "1.1,1.1",
}
]
๐Ÿ”น Example: Get Details of a Specific Agent
Request:
curl -X GET "http://localhost:8080/agents/1"
Response:
{
  "id": 1,
  "ip_address": "8.8.8.8",
    "asn": "15169",
    "isp": "Google LLC"
}

Running the API

Create a .env file
PORT=8080
DATABASE_URL=database.sqlite
RATE_LIMIT=100

install dependencies

go mod tidy

๐Ÿ”น Using Docker
  1. Clone the repository:
git clone https://github.com/Shaughny/obkio-test.git
  1. Start with docker:
make docker-run
  1. Read the logs:
make logs

4.Stop the container:

make docker-stop
๐Ÿ”น Using Local Go Installation
  1. Clone the repository:
git clone https://github.com/Shaughny/obkio-test.git
  1. Make sure go is installed on your machine.

  2. Run the API:

  • With make:
make run
  • Without make:
go run ./cmd/api/

๐Ÿ”น Running Tests
make test
๐Ÿ”น All make commands
make help
๐Ÿ”น Docker Without using make
  1. Clone the repository:
docker compose up -d --build
  1. Stop the container:
docker compose down

Removing binaries and database

make clean

Directories ยถ

Path Synopsis
cmd
api command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL