0scar
November 25, 2022, 7:38pm
1
Hi!!
If I run this
k6 run -e MY_HOSTNAME=test.k6.io script.js
I know how to retrieve an env value in the js script:
import http from 'k6/http';
import { sleep } from 'k6';
export default function () {
const res = http.get(`http://${__ENV.MY_HOSTNAME}/`);
sleep(1);
}
But how can I retrieve it from the go code in an extension? Did anyone achieve it?
I tried this but it do not work
os.LookupEnv("MY_HOSTNAME") (https://gobyexample.com/environment-variables)
Thanks very much
rdt.one
November 25, 2022, 11:57pm
2
Have you tried os.Getenv("MY_HOSTNAME")
?
1 Like
oleiade
November 28, 2022, 1:10pm
4
@0scar
as @rdt.one mentioned, os.Getenv
should be what you’re looking for
On top of that, because naming is hard, I wanted to raise your awareness that in your example what you referred to as a “hostname” was in fact a URL
0scar
December 4, 2022, 10:04pm
5
Hi,
Finally I understood how it works, and what I need is really os.Getenv(“MY_HOSTNAME”).
Many thanks for the answers!
1 Like