func GenLabelMap()

in api/internal/utils/utils.go [115:146]


func GenLabelMap(label string) (map[string]struct{}, error) {
	var err = errors.New("malformed label")
	mp := make(map[string]struct{})

	if label == "" {
		return mp, nil
	}

	labels := strings.Split(label, ",")
	for _, l := range labels {
		kv := strings.Split(l, ":")
		if len(kv) == 2 {
			if kv[0] == "" || kv[1] == "" {
				return nil, err
			}

			// Because the labels may contain the same key, like this: label=version:v1,version:v2
			// we need to combine them as a map's key
			mp[l] = struct{}{}
		} else if len(kv) == 1 {
			if kv[0] == "" {
				return nil, err
			}

			mp[kv[0]] = struct{}{}
		} else {
			return nil, err
		}
	}

	return mp, nil
}