|
Download task_047/instruction.md from Lego-X/UXInteract: direct link, hf CLI and curl.
- Browser
- Download file 1.94 kB
-
https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_047/instruction.md
- Command line
-
hf download hf://datasets/Lego-X/UXInteract/task_047/instruction.md
-
curl -L -o instruction.md https://huggingface.co/datasets/Lego-X/UXInteract/resolve/main/task_047/instruction.md
1.94 kB
| # Implement a pluggable HTTP log service | |
| Extend the supplied Go `loganalyzer` project. Separate log and tagging rules, application processing, persistence and the `net/http` interface so processing can be tested with an injected repository. Build and test offline with `go test ./...`. | |
| ## Interfaces | |
| - Keep `Log` with its string JSON fields `id`, `message`, `level`, `timestamp` and `tag`. | |
| - Keep `Repository` with `Save(Log) error` and `Get(id string) (Log, bool)`, and the constructors `NewMemoryRepository()`, `NewFileRepository(path)` and `NewRepositoryFromConfig(kind,path)` returning `Repository`. | |
| - Keep `GenerateTag(Log) string`, `NewService(repo) *Service`, `Service.Process(Log) (Log,error)` and `NewHandler(repo) http.Handler`. Generate a nonempty tag from the log (for example by level); no tagging taxonomy is prescribed. | |
| - Run the server with `go run ./cmd/server`. Default port is 8081; configure `PORT`, `STORAGE=memory|file` and the file path `LOG_FILE` through the environment. | |
| ## Acceptance Checklist | |
| - `POST /logs` accepts one JSON object with nonempty `id`, `message`, `level` and RFC3339 `timestamp`. Generate a tag, save the complete record and return it as JSON with a successful 2xx status. Trailing whitespace is allowed, but extra JSON values or other junk are not. | |
| - Malformed JSON or invalid fields return 400, leave no retrievable record, and do not disrupt later valid requests. `GET /log/:id` returns the full stored JSON record and 200 when found, or 404 when missing. Unsupported methods on either route return 405. | |
| - Memory storage supports immediate reads; file storage persists records in JSON or CSV and loads them after reopening or restarting the server. Preserve messages of at least 100 KiB in full. | |
| - A failed file write returns an error and leaves no unsaved record in memory. Creating missing parent directories is allowed; an unavailable destination must not give a success response. | |