From e0874d25f71f31bb9e5d8a9c7e1767050995c9f3 Mon Sep 17 00:00:00 2001 From: Tim Voronov Date: Wed, 17 Oct 2018 22:57:36 -0400 Subject: [PATCH] minor tweak in runtime.Options --- pkg/runtime/options.go | 12 ++++++++++-- pkg/runtime/program.go | 8 +------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/pkg/runtime/options.go b/pkg/runtime/options.go index 3b443eaf..3d09e3e0 100644 --- a/pkg/runtime/options.go +++ b/pkg/runtime/options.go @@ -22,7 +22,7 @@ type ( Option func(*Options) ) -func newOptions() *Options { +func NewOptions() *Options { return &Options{ cdp: "http://0.0.0.0:9222", params: make(map[string]core.Value), @@ -83,7 +83,15 @@ func WithLogLevel(lvl logging.Level) Option { } } -func (opts *Options) withContext(parent context.Context) context.Context { +func (opts *Options) Apply(setters ...Option) *Options { + for _, setter := range setters { + setter(opts) + } + + return opts +} + +func (opts *Options) WithContext(parent context.Context) context.Context { ctx := core.ParamsWith(parent, opts.params) ctx = logging.WithContext(ctx, opts.logging) ctx = env.WithContext(ctx, env.Environment{ diff --git a/pkg/runtime/program.go b/pkg/runtime/program.go index a85b6e97..dbca6b4a 100644 --- a/pkg/runtime/program.go +++ b/pkg/runtime/program.go @@ -33,13 +33,7 @@ func (p *Program) Run(ctx context.Context, setters ...Option) ([]byte, error) { defer closeFn() - opts := newOptions() - - for _, setter := range setters { - setter(opts) - } - - ctx = opts.withContext(ctx) + ctx = NewOptions().Apply(setters...).WithContext(ctx) ctx = html.WithDynamicDriver(ctx) ctx = html.WithStaticDriver(ctx)