| 53 | } |
| 54 | |
| 55 | func parseCustomFieldName(filePath string) error { |
| 56 | file, err := os.Open(filePath) |
| 57 | if err != nil { |
| 58 | return errkit.Wrap(err, "customfield: could not read field config") |
| 59 | } |
| 60 | defer func() { |
| 61 | if err := file.Close(); err != nil { |
| 62 | gologger.Error().Msgf("Error closing file: %v\n", err) |
| 63 | } |
| 64 | }() |
| 65 | |
| 66 | var data []CustomFieldConfig |
| 67 | if err := yaml.NewDecoder(file).Decode(&data); err != nil { |
| 68 | return errkit.Wrap(err, "customfield: could not decode field config") |
| 69 | } |
| 70 | passedCustomFieldMap := make(map[string]CustomFieldConfig) |
| 71 | for _, item := range data { |
| 72 | if !regexp.MustCompile(`^[A-Za-z0-9_-]+$`).MatchString(item.Name) { |
| 73 | return errkit.Newf("customfield: wrong custom field name %s", item.Name) |
| 74 | } |
| 75 | // check custom field name is pre-defined or not |
| 76 | if sliceutil.Contains(FieldNames, item.Name) { |
| 77 | return errkit.Newf("customfield: could not register custom field. \"%s\" already pre-defined field", item.Name) |
| 78 | } |
| 79 | // check custom field name should be unique |
| 80 | if _, ok := passedCustomFieldMap[item.Name]; ok { |
| 81 | return errkit.Newf("customfield: could not register custom field. \"%s\" custom field already exists", item.Name) |
| 82 | } |
| 83 | passedCustomFieldMap[item.Name] = item |
| 84 | } |
| 85 | return nil |
| 86 | } |
| 87 | |
| 88 | func loadCustomFields(filePath string, fields string) error { |
| 89 | var err error |