Skip to content

Commit 22ef7d4

Browse files
committed
Added paths objects helpers
1 parent 124db7f commit 22ef7d4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

objects.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
package properties
3131

32+
import (
33+
"github.com/arduino/go-paths-helper"
34+
)
35+
3236
// GetBoolean returns true if the map contains the specified key and the value
3337
// equals to the string "true", in any other case returns false.
3438
func (m Map) GetBoolean(key string) bool {
@@ -45,3 +49,22 @@ func (m Map) SetBoolean(key string, value bool) {
4549
m[key] = "false"
4650
}
4751
}
52+
53+
// GetPath returns a paths.Path object using the map value as path. The function
54+
// returns nil if the key is not present.
55+
func (m Map) GetPath(key string) *paths.Path {
56+
value, ok := m[key]
57+
if !ok {
58+
return nil
59+
}
60+
return paths.New(value)
61+
}
62+
63+
// SetPath saves the paths.Path object in the map using the path as value of the map
64+
func (m Map) SetPath(key string, value *paths.Path) {
65+
if value == nil {
66+
m[key] = ""
67+
} else {
68+
m[key] = value.String()
69+
}
70+
}

0 commit comments

Comments
 (0)