K6 as Golang Library

Can I use K6 as an engine behind a Golang HTTP server? Or maybe someone has done that already? :thinking:

Thinking so that the load test can be triggered via HTTP call and maybe passing the testing script in that call too

1 Like

Hi, welcome to the forum :slight_smile:

Have you taken a look at k6’s REST API or the k6 pause/resume/scale/etc. commands? Here’s a good guide on how to control a running test, which should be mostly up-to-date.

It’s currently not possible to pass it a script to run as you want, but you could automate this with some shell scripting that starts k6 with k6 run --paused and then use the API or the commands to control it at runtime.

That said, while there is no support for using k6 as a library, you could write a thin wrapper that starts the execution of specific scripts received over HTTP. I wouldn’t say it’s trivial, but now with Go module support this shouldn’t be much work if you’re comfortable with Go. Take a look at how the run command works, for example.

If you do get something working, please share it with the community! I doubt this would be merged into core k6, but maybe someone else would find it useful.




Thank you for the reply :smile: I’m planning to do the same! (making a light wrapper)