2022-11-19 23:11:19 +09:00
|
|
|
package cloudflare
|
2022-08-02 23:49:42 +09:00
|
|
|
|
2023-02-11 10:30:51 +09:00
|
|
|
import (
|
|
|
|
"context"
|
2023-03-20 10:42:06 +11:00
|
|
|
"syscall/js"
|
2023-02-12 01:50:16 +09:00
|
|
|
|
|
|
|
"github.com/syumai/workers/cloudflare/internal/cfruntimecontext"
|
2023-02-11 10:30:51 +09:00
|
|
|
)
|
2022-09-13 23:18:17 +09:00
|
|
|
|
2022-08-03 00:02:03 +09:00
|
|
|
// Getenv gets a value of an environment variable.
|
2022-08-03 00:19:01 +09:00
|
|
|
// - https://developers.cloudflare.com/workers/platform/environment-variables/
|
2023-02-11 10:30:51 +09:00
|
|
|
// - This function panics when a runtime context is not found.
|
|
|
|
func Getenv(ctx context.Context, name string) string {
|
2023-02-12 01:50:16 +09:00
|
|
|
return cfruntimecontext.GetRuntimeContextEnv(ctx).Get(name).String()
|
2022-08-02 23:49:42 +09:00
|
|
|
}
|
2023-03-20 10:42:06 +11:00
|
|
|
|
|
|
|
// GetBinding gets a value of an environment binding.
|
|
|
|
// - https://developers.cloudflare.com/workers/platform/bindings/about-service-bindings/
|
|
|
|
// - This function panics when a runtime context is not found.
|
|
|
|
func GetBinding(ctx context.Context, name string) js.Value {
|
|
|
|
return cfruntimecontext.GetRuntimeContextEnv(ctx).Get(name)
|
|
|
|
}
|