An open API service indexing awesome lists of open source software.

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

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"
```