Skip to content

Commit

Permalink
Conver init args to functional options (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Burnett authored Oct 2, 2018
1 parent 1cda3dd commit a0d6acf
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ func getFileSystemOp(ev fsnotify.Event) FileSystemOp {
return -1
}

const (
AllowDotFiles = false
IgnoreDotFiles = true
)
type Option func(l *Loader)

func AllowDotFiles(loader *Loader) { loader.ignoreDotfiles = false }
func IgnoreDotFiles(loader *Loader) { loader.ignoreDotfiles = true }

func New(runtimePath string, runtimeSubdirectory string, scope stats.Scope, refresher Refresher, ignoreDotfiles bool) IFace {
func New(runtimePath string, runtimeSubdirectory string, scope stats.Scope, refresher Refresher, opts ...Option) IFace {
if runtimePath == "" || runtimeSubdirectory == "" {
logger.Warnf("no runtime configuration. using nil loader.")
return NewNil()
Expand All @@ -181,8 +181,16 @@ func New(runtimePath string, runtimeSubdirectory string, scope stats.Scope, refr
}

newLoader := Loader{
watcher, runtimePath, runtimeSubdirectory, nil, nil, sync.RWMutex{}, nil,
newLoaderStats(scope), ignoreDotfiles}
watcher: watcher,
watchPath: runtimePath,
subdirectory: runtimeSubdirectory,
stats: newLoaderStats(scope),
}

for _, opt := range opts {
opt(&newLoader)
}

newLoader.onRuntimeChanged()

go func() {
Expand Down

0 comments on commit a0d6acf

Please sign in to comment.