From bac0abd44ba48a888bc9f249ca7c02bf9bf0daeb Mon Sep 17 00:00:00 2001 From: aki-0421 <118268728+aki-0421@users.noreply.github.com> Date: Wed, 17 Jan 2024 17:19:04 +0900 Subject: [PATCH] R: rename runtimecontext to cfcontext --- cloudflare/cron/cron.go | 3 +-- cloudflare/internal/cfruntimecontext/cfruntimecontext.go | 4 +--- handler.go | 3 +-- internal/{runtimecontext => cfcontext}/context.go | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) rename internal/{runtimecontext => cfcontext}/context.go (96%) diff --git a/cloudflare/cron/cron.go b/cloudflare/cron/cron.go index 9f6d6e1..aa6c279 100644 --- a/cloudflare/cron/cron.go +++ b/cloudflare/cron/cron.go @@ -8,7 +8,6 @@ import ( "time" "github.com/syumai/workers/internal/jsutil" - "github.com/syumai/workers/internal/runtimecontext" ) // Event represents information about the Cron that invoked this worker. @@ -42,7 +41,7 @@ func ScheduleTask(task Task) { } func runScheduler(eventObj js.Value, runtimeCtxObj js.Value) error { - ctx := runtimecontext.New(context.Background(), runtimeCtxObj) + ctx := cfcontext.New(context.Background(), runtimeCtxObj) event, err := toEvent(eventObj) if err != nil { return err diff --git a/cloudflare/internal/cfruntimecontext/cfruntimecontext.go b/cloudflare/internal/cfruntimecontext/cfruntimecontext.go index 731190d..41e7ea6 100644 --- a/cloudflare/internal/cfruntimecontext/cfruntimecontext.go +++ b/cloudflare/internal/cfruntimecontext/cfruntimecontext.go @@ -4,8 +4,6 @@ import ( "context" "errors" "syscall/js" - - "github.com/syumai/workers/internal/runtimecontext" ) /** @@ -49,7 +47,7 @@ var ErrValueNotFound = errors.New("execution context value for specified key not // GetRuntimeContextValue gets value for specified key from RuntimeContext. // - if the value is undefined, return error. func GetRuntimeContextValue(ctx context.Context, key string) (js.Value, error) { - runtimeCtxValue := runtimecontext.MustExtract(ctx) + runtimeCtxValue := cfcontext.MustExtract(ctx) v := runtimeCtxValue.Get(key) if v.IsUndefined() { return js.Value{}, ErrValueNotFound diff --git a/handler.go b/handler.go index d1d732c..396a166 100644 --- a/handler.go +++ b/handler.go @@ -9,7 +9,6 @@ import ( "github.com/syumai/workers/internal/jshttp" "github.com/syumai/workers/internal/jsutil" - "github.com/syumai/workers/internal/runtimecontext" ) var httpHandler http.Handler @@ -49,7 +48,7 @@ func handleRequest(reqObj js.Value, runtimeCtxObj js.Value) (js.Value, error) { if err != nil { panic(err) } - ctx := runtimecontext.New(context.Background(), runtimeCtxObj) + ctx := cfcontext.New(context.Background(), runtimeCtxObj) req = req.WithContext(ctx) reader, writer := io.Pipe() w := &jshttp.ResponseWriter{ diff --git a/internal/runtimecontext/context.go b/internal/cfcontext/context.go similarity index 96% rename from internal/runtimecontext/context.go rename to internal/cfcontext/context.go index aed2463..b14b168 100644 --- a/internal/runtimecontext/context.go +++ b/internal/cfcontext/context.go @@ -1,4 +1,4 @@ -package runtimecontext +package cfcontext import ( "context"