https://github.com/aeimer/go-error-simulator
HTTP Server with control over response code, latency, stdout and stderr
https://github.com/aeimer/go-error-simulator
Last synced: 8 months ago
JSON representation
HTTP Server with control over response code, latency, stdout and stderr
- Host: GitHub
- URL: https://github.com/aeimer/go-error-simulator
- Owner: aeimer
- License: mit
- Created: 2025-07-09T09:17:29.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-07-09T09:38:43.000Z (9 months ago)
- Last Synced: 2025-07-09T10:42:35.885Z (9 months ago)
- Language: Go
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-error-simulator
This simple app is an HTTP server which lets you control the response and behavior in several ways.
Options are:
* returned HTTP status code
* print text to STDOUT
* print text to STDERR
* add a (random) delay before returning the response
## Usage
**Run locally**
```
go run main.go
```
Then you can access the server at `http://localhost:8080`.
**Run via Docker**
```
docker run -p 8080:8080 -it --rm ghcr.io/aeimer/go-error-simulator:latest
```
Then you can access the server at `http://localhost:8080`.
## API
### `GET /`
Returns a simple HTML page with a link to the API documentation.
### `GET /simulate`
Simulates an error based on the query parameters. The following parameters are supported:
- `status`: HTTP status code to return (default: 200)
- `stdout`: text to print to STDOUT (default: empty)
- `stderr`: text to print to STDERR (default: empty)
- `latency`: delay in milliseconds before returning the response (default: 0)
- exact number: `latency=100`
- random range: `latency=100-200`
- random range shortcut: `latency=-100` (random between 0 and 100)
Examples:
```bash
curl "http://localhost:8080/simulate?status=200"
curl "http://localhost:8080/simulate?status=500&stdout=Hello%20World&stderr=Error%20Message&latency=100"
curl "http://localhost:8080/simulate?status=404&stdout=Not%20Found&latency=200-300"
curl "http://localhost:8080/simulate?status=200&stdout=OK&latency=-100"
```