mirror of
https://github.com/aykhans/sarin.git
synced 2026-02-28 14:59:14 +00:00
Fix config priority order (CLI > YAML > ENV), clarify multi-value cycling behavior, and improve documentation examples
This commit is contained in:
@@ -93,7 +93,7 @@ For more usage examples, see the **[Examples Guide](docs/examples.md)**.
|
|||||||
Sarin supports environment variables, CLI flags, and YAML files. When the same option is specified in multiple sources, the following priority order applies:
|
Sarin supports environment variables, CLI flags, and YAML files. When the same option is specified in multiple sources, the following priority order applies:
|
||||||
|
|
||||||
```
|
```
|
||||||
YAML (Highest) > CLI Flags > Environment Variables (Lowest)
|
CLI Flags (Highest) > YAML > Environment Variables (Lowest)
|
||||||
```
|
```
|
||||||
|
|
||||||
For detailed documentation on all configuration options (URL, method, timeout, concurrency, headers, cookies, proxy, etc.), see the **[Configuration Guide](docs/configuration.md)**.
|
For detailed documentation on all configuration options (URL, method, timeout, concurrency, headers, cookies, proxy, etc.), see the **[Configuration Guide](docs/configuration.md)**.
|
||||||
@@ -106,9 +106,9 @@ Sarin supports Go templates in URL paths, methods, bodies, headers, params, cook
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
sarin -U "http://example.com/users/{{ fakeit_UUID }}" -r 1000 -c 10 \
|
sarin -U "http://example.com/users/{{ fakeit_UUID }}" -r 1000 -c 10 \
|
||||||
-V "RequestID={{ fakeit_UUID }}" \
|
-V "REQUEST_ID={{ fakeit_UUID }}" \
|
||||||
-H "X-Request-ID: {{ .Values.RequestID }}" \
|
-H "X-Request-ID: {{ .Values.REQUEST_ID }}" \
|
||||||
-B '{"request_id": "{{ .Values.RequestID }}"}'
|
-B '{"request_id": "{{ .Values.REQUEST_ID }}"}'
|
||||||
```
|
```
|
||||||
|
|
||||||
For the complete templating guide and functions reference, see the **[Templating Guide](docs/templating.md)**.
|
For the complete templating guide and functions reference, see the **[Templating Guide](docs/templating.md)**.
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Sarin supports environment variables, CLI flags, and YAML files. However, they a
|
|||||||
When the same option is specified in multiple sources, the following priority order applies:
|
When the same option is specified in multiple sources, the following priority order applies:
|
||||||
|
|
||||||
```
|
```
|
||||||
YAML (Highest) > CLI Flags > Environment Variables (Lowest)
|
CLI Flags (Highest) > YAML > Environment Variables (Lowest)
|
||||||
```
|
```
|
||||||
|
|
||||||
Use `-s` or `--show-config` to see the final merged configuration before sending requests.
|
Use `-s` or `--show-config` to see the final merged configuration before sending requests.
|
||||||
@@ -14,8 +14,8 @@ Use `-s` or `--show-config` to see the final merged configuration before sending
|
|||||||
|
|
||||||
> **Note:** For CLI flags with `string / []string` type, the flag can be used once with a single value or multiple times to provide multiple values.
|
> **Note:** For CLI flags with `string / []string` type, the flag can be used once with a single value or multiple times to provide multiple values.
|
||||||
|
|
||||||
| Name | YAML | CLI | ENV | Default | Description |
|
| Name | YAML | CLI | ENV | Default | Description |
|
||||||
| --------------------------- | ----------------------------------- | --------------------------------------------- | -------------------------------- | ------- | ---------------------------- |
|
| --------------------------- | ----------------------------------- | -------------------------------------------- | -------------------------------- | ------- | ---------------------------- |
|
||||||
| [Help](#help) | - | `-help` / `-h` | - | - | Show help message |
|
| [Help](#help) | - | `-help` / `-h` | - | - | Show help message |
|
||||||
| [Version](#version) | - | `-version` / `-v` | - | - | Show version and build info |
|
| [Version](#version) | - | `-version` / `-v` | - | - | Show version and build info |
|
||||||
| [Show Config](#show-config) | `showConfig`<br>(boolean) | `-show-config` / `-s`<br>(boolean) | `SARIN_SHOW_CONFIG`<br>(boolean) | `false` | Show merged configuration |
|
| [Show Config](#show-config) | `showConfig`<br>(boolean) | `-show-config` / `-s`<br>(boolean) | `SARIN_SHOW_CONFIG`<br>(boolean) | `false` | Show merged configuration |
|
||||||
@@ -43,36 +43,65 @@ Use `-s` or `--show-config` to see the final merged configuration before sending
|
|||||||
|
|
||||||
Show help message.
|
Show help message.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sarin -help
|
||||||
|
```
|
||||||
|
|
||||||
## Version
|
## Version
|
||||||
|
|
||||||
Show version and build information.
|
Show version and build information.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sarin -version
|
||||||
|
```
|
||||||
|
|
||||||
## Show Config
|
## Show Config
|
||||||
|
|
||||||
Show the final merged configuration before sending requests.
|
Show the final merged configuration before sending requests.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
sarin -show-config
|
||||||
|
```
|
||||||
|
|
||||||
## Config File
|
## Config File
|
||||||
|
|
||||||
Path to configuration file(s). Supports local paths and remote URLs.
|
Path to configuration file(s). Supports local paths and remote URLs.
|
||||||
|
|
||||||
If multiple config files are specified, they are merged in order. Later files override earlier ones.
|
**Priority Rules:**
|
||||||
|
|
||||||
|
1. **CLI flags** (`-f`) have highest priority, processed left to right (rightmost wins)
|
||||||
|
2. **Included files** (via `configFile` property) are processed with lower priority than their parent
|
||||||
|
3. **Environment variable** (`SARIN_CONFIG_FILE`) has lowest priority
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# config2.yaml
|
# config2.yaml
|
||||||
configFile: /config4.yaml
|
configFile: /config4.yaml
|
||||||
|
url: http://from-config2.com
|
||||||
```
|
```
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
SARIN_CONFIG_FILE=/config1.yaml sarin -f /config2.yaml -f https://example.com/config3.yaml
|
SARIN_CONFIG_FILE=/config1.yaml sarin -f /config2.yaml -f https://example.com/config3.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
In this example, all 4 config files are read and merged with the following priority:
|
**Resolution order (lowest to highest priority):**
|
||||||
|
|
||||||
```
|
| Source | File | Priority |
|
||||||
config3.yaml > config2.yaml > config4.yaml > config1.yaml
|
| ------------------------ | ------------ | -------- |
|
||||||
```
|
| ENV (SARIN_CONFIG_FILE) | config1.yaml | Lowest |
|
||||||
|
| Included by config2.yaml | config4.yaml | ↑ |
|
||||||
|
| CLI -f (first) | config2.yaml | ↑ |
|
||||||
|
| CLI -f (second) | config3.yaml | Highest |
|
||||||
|
|
||||||
|
**Why this order?**
|
||||||
|
|
||||||
|
- `config1.yaml` comes from ENV → lowest priority
|
||||||
|
- `config2.yaml` comes from CLI → higher than ENV
|
||||||
|
- `config4.yaml` is included BY `config2.yaml` → inherits position below its parent
|
||||||
|
- `config3.yaml` comes from CLI after `config2.yaml` → highest priority
|
||||||
|
|
||||||
|
If all four files define `url`, the value from `config3.yaml` wins.
|
||||||
|
|
||||||
## URL
|
## URL
|
||||||
|
|
||||||
@@ -94,7 +123,7 @@ sarin -U "http://example.com/users/{{ fakeit_UUID }}" -r 1000 -c 10
|
|||||||
|
|
||||||
## Method
|
## Method
|
||||||
|
|
||||||
HTTP method(s). If multiple values are provided, Sarin cycles through them randomly for each request. Supports [templating](templating.md).
|
HTTP method(s). If multiple values are provided, Sarin cycles through them in order, starting from a random index for each request. Supports [templating](templating.md).
|
||||||
|
|
||||||
**YAML example:**
|
**YAML example:**
|
||||||
|
|
||||||
@@ -167,7 +196,7 @@ Skip TLS certificate verification.
|
|||||||
|
|
||||||
## Body
|
## Body
|
||||||
|
|
||||||
Request body. If multiple values are provided, Sarin cycles through them randomly for each request. Supports [templating](templating.md).
|
Request body. If multiple values are provided, Sarin cycles through them in order, starting from a random index for each request. Supports [templating](templating.md).
|
||||||
|
|
||||||
**YAML example:**
|
**YAML example:**
|
||||||
|
|
||||||
@@ -196,7 +225,7 @@ SARIN_BODY='{"product": "car"}'
|
|||||||
|
|
||||||
## Params
|
## Params
|
||||||
|
|
||||||
URL query parameters. If multiple values are provided for a key, Sarin cycles through them randomly for each request. Supports [templating](templating.md).
|
URL query parameters. If multiple values are provided for a key, Sarin cycles through them in order, starting from a random index for each request. Supports [templating](templating.md).
|
||||||
|
|
||||||
**YAML example:**
|
**YAML example:**
|
||||||
|
|
||||||
@@ -226,7 +255,7 @@ SARIN_PARAM="key1=value1"
|
|||||||
|
|
||||||
## Headers
|
## Headers
|
||||||
|
|
||||||
HTTP headers. If multiple values are provided for a key, Sarin cycles through them randomly for each request. Supports [templating](templating.md).
|
HTTP headers. If multiple values are provided for a key, Sarin cycles through them in order, starting from a random index for each request. Supports [templating](templating.md).
|
||||||
|
|
||||||
**YAML example:**
|
**YAML example:**
|
||||||
|
|
||||||
@@ -256,7 +285,7 @@ SARIN_HEADER="key1: value1"
|
|||||||
|
|
||||||
## Cookies
|
## Cookies
|
||||||
|
|
||||||
HTTP cookies. If multiple values are provided for a key, Sarin cycles through them randomly for each request. Supports [templating](templating.md).
|
HTTP cookies. If multiple values are provided for a key, Sarin cycles through them in order, starting from a random index for each request. Supports [templating](templating.md).
|
||||||
|
|
||||||
**YAML example:**
|
**YAML example:**
|
||||||
|
|
||||||
@@ -286,7 +315,7 @@ SARIN_COOKIE="key1=value1"
|
|||||||
|
|
||||||
## Proxy
|
## Proxy
|
||||||
|
|
||||||
Proxy URL(s). If multiple values are provided, Sarin cycles through them randomly for each request.
|
Proxy URL(s). If multiple values are provided, Sarin cycles through them in order, starting from a random index for each request.
|
||||||
|
|
||||||
Supported protocols: `http`, `https`, `socks5`, `socks5h`
|
Supported protocols: `http`, `https`, `socks5`, `socks5h`
|
||||||
|
|
||||||
|
|||||||
@@ -175,8 +175,8 @@ url: http://example.com/search
|
|||||||
requests: 1000
|
requests: 1000
|
||||||
concurrency: 10
|
concurrency: 10
|
||||||
params:
|
params:
|
||||||
query: test
|
query: "test"
|
||||||
limit: "10"
|
limit: 10
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
@@ -198,7 +198,7 @@ requests: 1000
|
|||||||
concurrency: 10
|
concurrency: 10
|
||||||
params:
|
params:
|
||||||
id: "{{ fakeit_IntRange 1 1000 }}"
|
id: "{{ fakeit_IntRange 1 1000 }}"
|
||||||
fields: name,email
|
fields: "name,email"
|
||||||
```
|
```
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|||||||
@@ -532,7 +532,7 @@ These functions are powered by [gofakeit](https://github.com/brianvoe/gofakeit)
|
|||||||
| Function | Description | Example |
|
| Function | Description | Example |
|
||||||
| ------------------------------------- | ------------------------------- | --------------------------------------------------------------- |
|
| ------------------------------------- | ------------------------------- | --------------------------------------------------------------- |
|
||||||
| `fakeit_Digit` | Single random digit | `"0"` |
|
| `fakeit_Digit` | Single random digit | `"0"` |
|
||||||
| `fakeit_DigitN(n uint)` | Generate `n` random digits | `{{ fakeit_DigitN 5 }}` → `"0136459948"` |
|
| `fakeit_DigitN(n uint)` | Generate `n` random digits | `{{ fakeit_DigitN 5 }}` → `"71364"` |
|
||||||
| `fakeit_Letter` | Single random letter | `"g"` |
|
| `fakeit_Letter` | Single random letter | `"g"` |
|
||||||
| `fakeit_LetterN(n uint)` | Generate `n` random letters | `{{ fakeit_LetterN 10 }}` → `"gbRMaRxHki"` |
|
| `fakeit_LetterN(n uint)` | Generate `n` random letters | `{{ fakeit_LetterN 10 }}` → `"gbRMaRxHki"` |
|
||||||
| `fakeit_Lexify(pattern string)` | Replace `?` with random letters | `{{ fakeit_Lexify "?????@??????.com" }}` → `"billy@mister.com"` |
|
| `fakeit_Lexify(pattern string)` | Replace `?` with random letters | `{{ fakeit_Lexify "?????@??????.com" }}` → `"billy@mister.com"` |
|
||||||
|
|||||||
Reference in New Issue
Block a user