average-number-service-go

module
v0.0.0-...-851419f Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT

README

Average Number Service

Description

Lightweight express app which calls a configured endpoint periodically and calculates a cumulative average of random numbers.

Behaviours and assumptions
  • The configured handler assumes a response type as detailed here https://csrng.net/documentation/csrng-lite/.

  • If any call to the endpoint returns an error, the application exits

    • This is to ensure any application runner/container can restart if required
  • The endpoint is subject to rate limiting, but in this use case it is not predicted to occur, as such any error of this nature is subject to the above.

    • If requirements favoured uptime instead of calling every second, then a retry mechanism with backoff would be introduced to adhere to the rate limit.
  • The latest number retrieved from the service is stored in memory, but instead of storing all collected numbers in memory the application calculates a cumulative average to avoid memory bloat over time.

Run

To start the service, run

go run main.go

Testing

There are unit tests to cover the functionality and an integration test to verify calling the express server.

To run

go test

Directories

Path Synopsis
internal
app

Jump to

Keyboard shortcuts

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