From ced0c3f516b2bc67480e5061a865cd6e7b543fa2 Mon Sep 17 00:00:00 2001 From: minhnhatnoe <86871862+minhnhatnoe@users.noreply.github.com> Date: Sat, 24 Jun 2023 22:54:35 +0700 Subject: [PATCH] Default settings local var --- worker/sandbox.go | 5 +---- worker/sandbox/settings.go | 10 +++++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/worker/sandbox.go b/worker/sandbox.go index 9b876a0..41a6865 100644 --- a/worker/sandbox.go +++ b/worker/sandbox.go @@ -8,10 +8,7 @@ import ( ) func NewSandbox(name string, options ...sandbox.Option) (sandbox.Runner, error) { - setting := sandbox.DefaultSettings - for _, option := range options { - setting = option(setting) - } + setting := sandbox.MakeSettings(options...) switch name { case "raw": return raw.New(setting), nil diff --git a/worker/sandbox/settings.go b/worker/sandbox/settings.go index ef528ad..8cbd68a 100644 --- a/worker/sandbox/settings.go +++ b/worker/sandbox/settings.go @@ -5,7 +5,7 @@ type Settings struct { IgnoreWarning bool } -var DefaultSettings = Settings{LogSandbox: true, IgnoreWarning: false} +var defaultSettings = Settings{LogSandbox: true, IgnoreWarning: false} type Option func(Settings) Settings @@ -22,3 +22,11 @@ func EnableSandboxLogs(enable bool) Option { return o } } + +func MakeSettings(options ...Option) Settings { + setting := defaultSettings + for _, option := range options { + setting = option(setting) + } + return setting +}