| 1 |
package filesystems |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"strings" |
| 6 |
) |
| 7 |
|
| 8 |
func buildProperties(input map[string]string) string { |
| 9 |
// properties has to be a comma-separated key-value pair |
| 10 |
properties := make([]string, 0) |
| 11 |
|
| 12 |
for k, v := range input { |
| 13 |
properties = append(properties, fmt.Sprintf("%s=%s", k, v)) |
| 14 |
} |
| 15 |
|
| 16 |
return strings.Join(properties, ",") |
| 17 |
} |
| 18 |
|
| 19 |
func parseProperties(input string) (*map[string]string, error) { |
| 20 |
properties := make(map[string]string) |
| 21 |
if input == "" { |
| 22 |
return &properties, nil |
| 23 |
} |
| 24 |
|
| 25 |
// properties is a comma-separated list of key-value pairs |
| 26 |
splitProperties := strings.Split(input, ",") |
| 27 |
for _, propertyRaw := range splitProperties { |
| 28 |
// because these are base64-encoded they're likely to end in at least one = |
| 29 |
// as such we can't string split on that -_- |
| 30 |
position := strings.Index(propertyRaw, "=") |
| 31 |
if position < 0 { |
| 32 |
return nil, fmt.Errorf("Expected there to be an equals in the key value pair: %q", propertyRaw) |
| 33 |
} |
| 34 |
|
| 35 |
key := propertyRaw[0:position] |
| 36 |
value := propertyRaw[position+1:] |
| 37 |
properties[key] = value |
| 38 |
} |
| 39 |
return &properties, nil |
| 40 |
} |