func GetContentType(path string) (string, error) {
	fileStat, err := os.Stat(path)
	if err != nil {
		return "", err
	}
	if fileStat.Size() == 0 {
		return "", nil
	}
	file, err := os.Open(path)
	if err != nil {
		return "", err
	}
	defer file.Close()
	buffer := make([]byte, 512)
	_, err = file.Read(buffer)
	if err != nil {
		return "", err
	}
	_, err = file.Seek(0, 0)
	if err != nil {
		panic(err)
	}
	return http.DetectContentType(buffer), nil
}
GetContentType returns the content type of a file
package files
import (
	"bufio"
	"fmt"
	"net/http"
	"os"
	"os/exec"
	"path/filepath"
	"regexp"
	"strings"
	"github.com/editorconfig/editorconfig-core-go/v2"
	"github.com/editorconfig-checker/editorconfig-checker/pkg/config"
	"github.com/editorconfig-checker/editorconfig-checker/pkg/utils"
)
type FileInformation struct {
	Line         string
	Content      string
	FilePath     string
	LineNumber   int
	Editorconfig *editorconfig.Definition
}
func IsExcluded(filePath string, config config.Config) (bool, error) {
	if len(config.Exclude) == 0 && config.IgnoreDefaults {
		return false, nil
	}
	relativeFilePath, err := GetRelativePath(filePath)
	if err != nil {
		return true, err
	}
	result, err := regexp.MatchString(config.GetExcludesAsRegularExpression(), relativeFilePath)
	if err != nil {
		return true, err
	}
	return result, nil
}
func AddToFiles(filePaths []string, filePath string, config config.Config) []string {
	contentType, err := GetContentType(filePath)
	config.Logger.Debug("AddToFiles: filePath: %s, contentType: %s", filePath, contentType)
	if err != nil {
		config.Logger.Error("Could not get the ContentType of file: %s", filePath)
		config.Logger.Error(err.Error())
	}
	isExcluded, err := IsExcluded(filePath, config)
	if err == nil && !isExcluded && IsAllowedContentType(contentType, config) {
		config.Logger.Verbose("Add %s to be checked", filePath)
		return append(filePaths, filePath)
	}
	config.Logger.Verbose("Don't add %s to be checked", filePath)
	return filePaths
}
func GetFiles(config config.Config) ([]string, error) {
	var filePaths []string
	if len(config.PassedFiles) != 0 {
		for _, passedFile := range config.PassedFiles {
			if utils.IsDirectory(passedFile) {
				_ = filepath.Walk(passedFile, func(path string, fi os.FileInfo, err error) error {
					if fi.Mode().IsRegular() {
						filePaths = AddToFiles(filePaths, path, config)
					}
					return nil
				})
			} else {
				filePaths = AddToFiles(filePaths, passedFile, config)
			}
		}
		return filePaths, nil
	}
	byteArray, err := exec.Command("git", "ls-files", "--cached", "--others", "--modified", "--exclude-standard").Output()
	if err != nil {
		cwd, err := os.Getwd()
		if err != nil {
			return filePaths, err
		}
		_ = filepath.Walk(cwd, func(path string, fi os.FileInfo, err error) error {
			if fi.Mode().IsRegular() {
				filePaths = AddToFiles(filePaths, path, config)
			}
			return nil
		})
	}
	filesSlice := strings.Split(string(byteArray[:]), "\n")
	for _, filePath := range filesSlice {
		if len(filePath) > 0 {
			fi, err := os.Stat(filePath)
			if err == nil && fi.Mode().IsRegular() {
				filePaths = AddToFiles(filePaths, filePath, config)
			}
		}
	}
	return filePaths, nil
}
func ReadLines(filePath string) []string {
	var lines []string
	fileHandle, _ := os.Open(filePath)
	defer fileHandle.Close()
	fileScanner := bufio.NewScanner(fileHandle)
	for fileScanner.Scan() {
		lines = append(lines, fileScanner.Text())
	}
	return lines
}