repository
0.0.0-20241117095027-ea831ad319f9
Repository: https://github.com/glauco/proglog.git
Documentation: pkg.go.dev
# README
ProgLog HTTP Server
A simple HTTP server component that provides endpoints to manage a log of records, allowing clients to produce and consume records over HTTP. This server is designed to handle concurrent requests safely.
Features
- Produce Records: Add new records to the log via an HTTP POST request.
- Consume Records: Retrieve records from the log by their offset via an HTTP GET request.
- Concurrency Safe: Uses a mutex to ensure thread-safe access to the log.
Getting Started
Prerequisites
- Go (1.16 or later)
Installation
- Clone this repository:
git clone https://github.com/glauco/proglog.git cd proglog
- Install dependencies:
go mod download
Running the Server
To start the server, navigate to the root directory and run the following command:
go run cmd/server/main.go
This will start the server on port 9090
.
Usage
The server exposes two main endpoints to interact with the log:
- Produce (Add a Record)
- URL:
/
- Method:
POST
- Body (encoded in
base64
):{ "record": { "value": "SGVsbG8sIFdvcmxkCg==" } }
- Response:
200 OK
:{ "offset": <record_offset> }
if the record is successfully added.400 Bad Request
: If the request format is invalid.500 Internal Server Error
: If there is an issue with appending the record.
- Consume (Retrieve a Record)
- URL:
/
- Method:
GET
- Body:
{ "offset": 0 }
- Response:
200 OK
:{ "record": { "value": ""SGVsbG8sIFdvcmxkCg=="", "offset": 0 } }
400 Bad Request
: If the request format is invalid.500 Internal Server Error
: If the requested offset is not found or there is a server issue.