-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
199 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cy | ||
|
||
import ( | ||
"github.com/cfoust/cy/pkg/cy/params" | ||
) | ||
|
||
func (c *Cy) setDefaults(options Options) error { | ||
defaults := map[string]interface{}{ | ||
params.ParamDataDirectory: options.DataDir, | ||
} | ||
|
||
for key, value := range defaults { | ||
err := c.defaults.Set(key, value) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package params | ||
|
||
const ( | ||
// The directory in which .borg files will be saved. | ||
ParamDataDirectory = "data-dir" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package params | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cfoust/cy/pkg/janet" | ||
|
||
"github.com/sasha-s/go-deadlock" | ||
) | ||
|
||
type Parameters struct { | ||
deadlock.RWMutex | ||
parent *Parameters | ||
table map[string]interface{} | ||
} | ||
|
||
func (p *Parameters) Set(key string, value interface{}) error { | ||
if !janet.IsValidType(value) { | ||
return fmt.Errorf("all parameters must be representable in Janet") | ||
} | ||
|
||
p.Lock() | ||
p.table[key] = value | ||
p.Unlock() | ||
return nil | ||
} | ||
|
||
func (p *Parameters) Get(key string) (value interface{}, ok bool) { | ||
var current *Parameters = p | ||
for current != nil { | ||
current.RLock() | ||
value, ok = current.table[key] | ||
current.RUnlock() | ||
if ok { | ||
return value, ok | ||
} | ||
current = current.parent | ||
} | ||
|
||
return nil, false | ||
} | ||
|
||
func (p *Parameters) NewChild() *Parameters { | ||
child := New() | ||
child.parent = p | ||
return child | ||
} | ||
|
||
func New() *Parameters { | ||
return &Parameters{ | ||
table: make(map[string]interface{}), | ||
} | ||
} |