23 lines
791 B
Go
Raw Normal View History

package cloudflare
2022-08-02 23:49:42 +09:00
2023-02-11 10:30:51 +09:00
import (
"context"
"syscall/js"
"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 {
return cfruntimecontext.MustGetRuntimeContextEnv(ctx).Get(name).String()
2022-08-02 23:49:42 +09: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.MustGetRuntimeContextEnv(ctx).Get(name)
}