func (s *File) labelExists(label string) bool {
	for _, l := range s.labels {
		if l == label {
			return true
		}
	}
	return false
}
labelExists returns bool if label exists in yaml
package file
import (
	"bytes"
	"errors"
	"fmt"
	"github.com/mattes/go-collect/data"
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"net/url"
	"os"
	"path/filepath"
	"regexp"
)
var (
	ErrEmptyPath   = errors.New("source: file: no path given")
	ErrYamlParsing = errors.New("source: file: yaml parsing failed")
	ErrYamlLevels  = errors.New("source: file: only 2 levels of indentation allowed")
)
type File struct {
	label string
	url   *url.URL
	path  string
	body []byte
	yaml map[string]map[string][]string
	labels []string
}
func (s *File) Scheme() string {
	return "file"
}
func (s *File) ExampleUrl() string {
	return "file://config.yml"
}
func (s *File) Load(label string, u *url.URL) (*data.Data, error) {
	s.url = u
	s.setPathFromUrl()
	if err := s.readFile(); err != nil {
		return nil, err
	}
	if err := s.parse(); err != nil {
		return nil, err
	}
	s.label = s.selectLabel(label)
	if s.label == "" {
		s.label = s.selectLabel("")
	}
	return s.getData(), nil
}
func (s *File) Labels() []string {
	return s.labels
}
func (s *File) setPathFromUrl() {
	if s.url.Host == "" {
		s.path = s.url.Path
	} else {
		s.path = s.url.Host + "/" + s.url.Path
		s.path, _ = filepath.Abs(s.path)
	}
}
func (s *File) readFile() error {
	if s.path == "" {
		return ErrEmptyPath
	}
	body, err := ioutil.ReadFile(s.path)
	if err != nil {
		return fmt.Errorf("source: file: %v", err.Error())
	}
	s.body = body
	return nil
}
func (s *File) parse() error {
	s.body = injectEnvVars(s.body)
	reRepl := regexp.MustCompile("^\\s*(<<:)")
	spl := bytes.Split(s.body, []byte("\n"))
	for i := 0; i < len(spl); i++ {
		spl[i] = reRepl.ReplaceAllFunc(spl[i], func(in []byte) []byte {
			return bytes.Replace(in, []byte("<<:"), []byte("<: "), 1)
		})
	}
	s.body = bytes.Join(spl, []byte("\n"))
	hasLabels := true
	var yamlWithLabels map[string]map[string]interface{}
	if err := yaml.Unmarshal(s.body, &yamlWithLabels); err != nil {
		var yamlNoLabels map[string]interface{}
		if err := yaml.Unmarshal(s.body, &yamlNoLabels); err != nil {
			return ErrYamlParsing
		}
		yamlWithLabels = map[string]map[string]interface{}{
			"default": yamlNoLabels,
		}
		hasLabels = false
	}
	s.yaml = make(map[string]map[string][]string)
	for k, v := range yamlWithLabels {
		s.yaml[k] = make(map[string][]string)
		for k2, v2 := range v {
			s.yaml[k][k2] = make([]string, 0)
			switch v2.(type) {
			case []interface{}:
				s.yaml[k][k2] = interfaceSliceToStringSlice(v2.([]interface{}))
			case map[interface{}]interface{}:
				return ErrYamlLevels
			default:
				s.yaml[k][k2] = []string{fmt.Sprintf("%v", v2)}
			}
		}
	}
	allParsed := false
	for !allParsed {
		allParsed = true
		for label, vs := range s.yaml {
			for k, v := range vs {
				if k == "<" {
					if len(v) != 1 {
						return ErrYamlParsing
					}
					delete(s.yaml[label], k)
					if refLabel, ok := s.yaml[v[0]]; ok {
						for k, v := range refLabel {
							if _, exists := vs[k]; !exists {
								s.yaml[label][k] = v
							}
							if k == "<" {
								allParsed = false
							}
						}
					}
				}
			}
		}
	}
	if hasLabels {
		var labelOrder yaml.MapSlice
		if err := yaml.Unmarshal(s.body, &labelOrder); err != nil {
			return ErrYamlParsing
		}
		s.labels = make([]string, 0)
		for _, v := range labelOrder {
			s.labels = append(s.labels, v.Key.(string))
		}
	} else {
		s.labels = []string{"default"}
	}
	return nil
}