Skip to content

Commit

Permalink
Default settings local var
Browse files Browse the repository at this point in the history
  • Loading branch information
minhnhatnoe committed Jun 24, 2023
1 parent 7e7822f commit ced0c3f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
5 changes: 1 addition & 4 deletions worker/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion worker/sandbox/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}

0 comments on commit ced0c3f

Please sign in to comment.