A simple project to run HTTP load tests using Go as a wrapper for k6. Configuration (VUs, target URL, duration) is read from a config.json file so you can adjust parameters without changing the code.
This project is a load testing software designed to measure the resilience of websites. We are not responsible if it is used outside of legal and ethical frameworks!
- Read test parameters (VUs, duration, target URL) from JSON config
- Go wrapper injects environment variables into k6 script
- Simple Go executable launches k6 load test
- No extra dependencies beyond Go and k6
K6-Load-Test/
├─ go.mod # Go module file
├─ config.json # Test configuration file
├─ main.go # Go wrapper for k6
└─ loadtest.js # k6 script for HTTP requests
Edit config.json to set your test parameters:
{
"vus": 1000, // Number of virtual users
"duration": "60s", // Total duration (e.g. "30s", "2m", "1h")
"target_url": "https://example.com" // Endpoint to test
}Note: The target_url value is read by the Go program and passed to the k6 script via an environment variable (TARGET_URL). The k6 script itself does not read config.json directly.
-
Clone the repository:
git clone https://github.com/nuekkis/K6-Load-Test.git cd K6-Load-Test -
Ensure Go modules are initialized:
go mod tidy
-
Verify k6 is installed:
k6 version
Run the Go application, which will:
- Read
config.jsonfor VUs, duration, and target URL. - Set the
TARGET_URLenvironment variable for k6. - Launch the k6 script with the provided parameters.
go run main.goYou will see k6 output, including metrics like requests per second, response times, and checks.
-
Read Config:
main.goreadsconfig.jsonand parses it into a Go struct. -
Build Command: Constructs the command:
k6 run --vus <VUs> --duration <Duration> loadtest.js
-
Inject Env Var: Sets
TARGET_URLin the environment for the k6 process, using the value fromconfig.json. -
Execute: Runs k6 and streams the results to the console.
In loadtest.js, k6 accesses the URL via __ENV.TARGET_URL:
import http from 'k6/http';
import { check, sleep } from 'k6';
export default function () {
const res = http.get(__ENV.TARGET_URL);
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}Contributions are welcome! Feel free to:
- Open an issue for bugs or feature requests
- Submit pull requests with improvements
Please follow standard GitHub flow:
- Fork the repo
- Create a feature branch
- Commit your changes
- Open a pull request
This project is licensed under the MIT License. See LICENSE for details.