go-runtime is a Go helper package for accessing runtime information for a Kavun Cloud (hereinafter referred to as "KC") application instance.
It reads the immutable runtime manifest exposed to managed services and provides equivalent defaults for local development, allowing programs to be tested outside KC.
Usage is fairly simple. As the library is intended to be "dumb", it does not know whether
it is actually running on KC. Instead, you must specify that explicitly through the Mode
field of kavuncloud.Options.
Usually, selecting between kavuncloud.Managed and kavuncloud.Development is done based
on a user-specified production boolean.
We did not want to "assume KC if runtime.json exists" or silently fall back to something else, which is why the Managed vs Development distinction is manual.
environment, err:=kavuncloud.Load(kavuncloud.Options{
Mode: kavuncloud.Managed,
})
iferr!=nil {
returnerr
}
listener, err:=environment.Listener("http")
secret, err:=environment.GetSecret("ApiKey")Managed mode requires the runtime manifest at /run/kavuncloud/runtime.json.
Development mode lets you provide local equivalents for resources that KC would normally supply.
environment, err:=kavuncloud.Load(kavuncloud.Options{
Mode: kavuncloud.Development,
Development: kavuncloud.DevelopmentOptions{
ProjectName: "Passport",
ApplicationName: "Passport API",
Drives: map[string]kavuncloud.Drive{
"data": {Path: ".data"},
},
},
})Unless explicitly overridden, development mode uses the following defaults:
- System: the current working directory
- Runtime:
.data/runtime/ - Temporary: the operating system's temporary directory
- Secrets:
.env/(yes, as a directory, not a file)