Skip to content

Commit 2ae6e1a

Browse files
authored
Merge pull request #187 from marquiz/devel/cache-refactor
chore: simplify cache Option type
2 parents 97d2e84 + 64cfcc9 commit 2ae6e1a

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

pkg/cdi/cache.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
)
3434

3535
// Option is an option to change some aspect of default CDI behavior.
36-
type Option func(*Cache) error
36+
type Option func(*Cache)
3737

3838
// Cache stores CDI Specs loaded from Spec directories.
3939
type Cache struct {
@@ -54,9 +54,8 @@ type Cache struct {
5454
// is detected. This option can be used to disable this behavior when a
5555
// manually refreshed mode is preferable.
5656
func WithAutoRefresh(autoRefresh bool) Option {
57-
return func(c *Cache) error {
57+
return func(c *Cache) {
5858
c.autoRefresh = autoRefresh
59-
return nil
6059
}
6160
}
6261

@@ -92,12 +91,8 @@ func (c *Cache) Configure(options ...Option) error {
9291
// Configure the Cache. Start/stop CDI Spec directory watch, refresh
9392
// the Cache if necessary.
9493
func (c *Cache) configure(options ...Option) error {
95-
var err error
96-
9794
for _, o := range options {
98-
if err = o(c); err != nil {
99-
return fmt.Errorf("failed to apply cache options: %w", err)
100-
}
95+
o(c)
10196
}
10297

10398
c.dirErrors = make(map[string]error)

pkg/cdi/spec-dirs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@ var (
4444

4545
// WithSpecDirs returns an option to override the CDI Spec directories.
4646
func WithSpecDirs(dirs ...string) Option {
47-
return func(c *Cache) error {
47+
return func(c *Cache) {
4848
specDirs := make([]string, len(dirs))
4949
for i, dir := range dirs {
5050
specDirs[i] = filepath.Clean(dir)
5151
}
5252
c.specDirs = specDirs
53-
return nil
5453
}
5554
}
5655

0 commit comments

Comments
 (0)