runtime
is a Starlark module provides Go and app runtime information.
hostname
: A string representing the hostname of the system where the script is being executed.workdir
: A string representing the current working directory of the process.homedir
: A string representing the home directory of the user running the process, it's$HOME
on Unix/Linux,%USERPROFILE%
on Windows.os
: A string representing the operating system of the runtime. This value comes from Go'sruntime.GOOS
.arch
: A string representing the architecture of the machine. This value is derived from Go'sruntime.GOARCH
.gover
: A string representing the Go runtime version. This is obtained usingruntime.Version()
from the Go standard library.pid
: An integer representing the process ID of the current process.ppid
: An integer representing the parent process ID of the current process.uid
: An integer representing the user ID of the process owner.gid
: An integer representing the group ID of the process owner.app_start
: A time value representing the moment when the application started. This is used to calculate uptime.
Returns the uptime of the current process in time.duration
.
basic
Returns the uptime of the current process immediately.
load("runtime", "uptime")
print(uptime())
# Output: 883.583µs
Returns the value of the environment variable key as a string if it exists, or default if it doesn't.
basic
Returns the value of the environment variable PATH if it exists, or None if it doesn't.
load("runtime", "getenv")
print(getenv("PATH"))
# Output: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Sets the value of the environment variable named by the key, returning an error if any.
basic
Sets the environment variable STARLET_TEST
to the value 123456
.
load("runtime", "putenv")
putenv("STARLET_TEST", 123456)
Sets the value of the environment variable named by the key, returning an error if any.
Alias of putenv
.
basic
Sets the environment variable STARLET_TEST
to the value ABC
.
load("runtime", "setenv")
setenv("STARLET_TEST", "ABC")
Unsets a single environment variable.
basic
Unsets the environment variable STARLET_TEST.
load("runtime", "unsetenv")
unsetenv("STARLET_TEST")