getStringField extracts a string field from a record map. If required is true, it returns an error if the field is missing, nil, empty, or not a string. If required is false, it returns an empty string without error if the field is missing or nil, but returns an error if the field exists and is not
(record map[string]interface{}, fieldName string, required bool)
| 297 | // If required is false, it returns an empty string without error if the field is missing or nil, |
| 298 | // but returns an error if the field exists and is not a string. |
| 299 | func getStringField(record map[string]interface{}, fieldName string, required bool) (string, errors.Error) { |
| 300 | value, ok := record[fieldName] |
| 301 | if !ok || value == nil { |
| 302 | if required { |
| 303 | return "", errors.Default.New(fmt.Sprintf("record without required field %s", fieldName)) |
| 304 | } |
| 305 | return "", nil // Field missing or nil, but not required |
| 306 | } |
| 307 | |
| 308 | strValue, ok := value.(string) |
| 309 | if !ok { |
| 310 | return "", errors.Default.New(fmt.Sprintf("%s is not a string", fieldName)) |
| 311 | } |
| 312 | |
| 313 | if required && strValue == "" { |
| 314 | return "", errors.Default.New(fmt.Sprintf("invalid or empty required field %s", fieldName)) |
| 315 | } |
| 316 | |
| 317 | return strValue, nil |
| 318 | } |
| 319 | |
| 320 | // issueHandlerFactory returns a handler that save record into `issues`, `board_issues` and `issue_labels` table |
| 321 | func (s *Service) issueHandlerFactory(boardId string, incremental bool) func(record map[string]interface{}) errors.Error { |