(path string)
| 1070 | } |
| 1071 | |
| 1072 | func ReadProps(path string) (map[string]string, error) { |
| 1073 | |
| 1074 | props := map[string]string{} |
| 1075 | |
| 1076 | file, err := os.Open(path) |
| 1077 | if err != nil { |
| 1078 | // If file does not exist, just return props |
| 1079 | whisk.Debug(whisk.DbgWarn, "Unable to read whisk properties file '%s' (file open error: %s); falling back to default properties\n", path, err) |
| 1080 | return props, nil |
| 1081 | } |
| 1082 | defer file.Close() |
| 1083 | |
| 1084 | lines := []string{} |
| 1085 | scanner := bufio.NewScanner(file) |
| 1086 | for scanner.Scan() { |
| 1087 | lines = append(lines, scanner.Text()) |
| 1088 | } |
| 1089 | |
| 1090 | props = map[string]string{} |
| 1091 | for _, line := range lines { |
| 1092 | re := regexp.MustCompile("#.*") |
| 1093 | line = re.ReplaceAllString(line, "") |
| 1094 | line = strings.TrimSpace(line) |
| 1095 | kv := strings.Split(line, "=") |
| 1096 | if len(kv) != 2 { |
| 1097 | // Invalid format; skip |
| 1098 | continue |
| 1099 | } |
| 1100 | props[kv[0]] = kv[1] |
| 1101 | } |
| 1102 | |
| 1103 | return props, nil |
| 1104 | |
| 1105 | } |
| 1106 | |
| 1107 | func WriteProps(path string, props map[string]string) error { |
| 1108 |
no outgoing calls
no test coverage detected