mirror of
https://github.com/syumai/workers.git
synced 2025-03-10 17:29:11 +00:00
move cloudflare's runtimecontext to cloudflare/internal package
This commit is contained in:
parent
35fd1e00a0
commit
c7f74f0e94
@ -2,11 +2,13 @@ package cloudflare
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/syumai/workers/cloudflare/internal/cfruntimecontext"
|
||||
)
|
||||
|
||||
// Getenv gets a value of an environment variable.
|
||||
// - https://developers.cloudflare.com/workers/platform/environment-variables/
|
||||
// - This function panics when a runtime context is not found.
|
||||
func Getenv(ctx context.Context, name string) string {
|
||||
return getRuntimeContextEnv(ctx).Get(name).String()
|
||||
return cfruntimecontext.GetRuntimeContextEnv(ctx).Get(name).String()
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cloudflare
|
||||
package cfruntimecontext
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -19,17 +19,17 @@ import (
|
||||
* - see: https://github.com/cloudflare/workers-types/blob/c8d9533caa4415c2156d2cf1daca75289d01ae70/index.d.ts#LL564
|
||||
*/
|
||||
|
||||
// getRuntimeContextEnv gets object which holds environment variables bound to Cloudflare worker.
|
||||
// GetRuntimeContextEnv gets object which holds environment variables bound to Cloudflare worker.
|
||||
// - see: https://github.com/cloudflare/workers-types/blob/c8d9533caa4415c2156d2cf1daca75289d01ae70/index.d.ts#L566
|
||||
func getRuntimeContextEnv(ctx context.Context) js.Value {
|
||||
func GetRuntimeContextEnv(ctx context.Context) js.Value {
|
||||
runtimeCtxValue := runtimecontext.MustExtract(ctx)
|
||||
return runtimeCtxValue.Get("env")
|
||||
}
|
||||
|
||||
// getExecutionContext gets ExecutionContext object from context.
|
||||
// GetExecutionContext gets ExecutionContext object from context.
|
||||
// - see: https://github.com/cloudflare/workers-types/blob/c8d9533caa4415c2156d2cf1daca75289d01ae70/index.d.ts#L567
|
||||
// - see also: https://github.com/cloudflare/workers-types/blob/c8d9533caa4415c2156d2cf1daca75289d01ae70/index.d.ts#L554
|
||||
func getExecutionContext(ctx context.Context) js.Value {
|
||||
func GetExecutionContext(ctx context.Context) js.Value {
|
||||
runtimeCtxValue := runtimecontext.MustExtract(ctx)
|
||||
return runtimeCtxValue.Get("ctx")
|
||||
}
|
@ -6,6 +6,8 @@ import (
|
||||
"io"
|
||||
"syscall/js"
|
||||
|
||||
"github.com/syumai/workers/cloudflare/internal/cfruntimecontext"
|
||||
|
||||
"github.com/syumai/workers/internal/jsutil"
|
||||
)
|
||||
|
||||
@ -21,7 +23,7 @@ type KVNamespace struct {
|
||||
// - if the given variable name doesn't exist on runtime context, returns error.
|
||||
// - This function panics when a runtime context is not found.
|
||||
func NewKVNamespace(ctx context.Context, varName string) (*KVNamespace, error) {
|
||||
inst := getRuntimeContextEnv(ctx).Get(varName)
|
||||
inst := cfruntimecontext.GetRuntimeContextEnv(ctx).Get(varName)
|
||||
if inst.IsUndefined() {
|
||||
return nil, fmt.Errorf("%s is undefined", varName)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
"syscall/js"
|
||||
|
||||
"github.com/syumai/workers/cloudflare/internal/cfruntimecontext"
|
||||
"github.com/syumai/workers/internal/jsutil"
|
||||
)
|
||||
|
||||
@ -22,7 +23,7 @@ type R2Bucket struct {
|
||||
// - if the given variable name doesn't exist on runtime context, returns error.
|
||||
// - This function panics when a runtime context is not found.
|
||||
func NewR2Bucket(ctx context.Context, varName string) (*R2Bucket, error) {
|
||||
inst := getRuntimeContextEnv(ctx).Get(varName)
|
||||
inst := cfruntimecontext.GetRuntimeContextEnv(ctx).Get(varName)
|
||||
if inst.IsUndefined() {
|
||||
return nil, fmt.Errorf("%s is undefined", varName)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user