func createValue(store *storage.Storage, tx *storage.Tx, valueName string) (*entities.Value, error) { value, err := store.AddValue(tx, valueName) if err != nil { return nil, err } log.Warnf("new value '%v'", valueName) return value, nil }
func createTagsValues(store *storage.Storage, tx *storage.Tx, tagArgs []string) (error, warnings) { warnings := make(warnings, 0, 10) for _, tagArg := range tagArgs { name := parseTagOrValueName(tagArg) if name[0] == '=' { name = name[1:] value, err := store.ValueByName(tx, name) if err != nil { return fmt.Errorf("could not check if value '%v' exists: %v", name, err), warnings } if value == nil { if _, err := store.AddValue(tx, name); err != nil { return fmt.Errorf("could not create value '%v': %v", name, err), warnings } } else { warnings = append(warnings, fmt.Sprintf("value '%v' already exists", name)) } } else { tag, err := store.TagByName(tx, name) if err != nil { return fmt.Errorf("could not check if tag '%v' exists: %v", name, err), warnings } if tag == nil { if _, err := store.AddTag(tx, name); err != nil { return fmt.Errorf("could not create tag '%v': %v", name, err), warnings } } else { warnings = append(warnings, fmt.Sprintf("tag '%v' already exists", name)) } } } return nil, warnings }