github.com/Files-com/files-sdk-go/v2@v2.1.2/ignore/main.go (about) 1 package ignore 2 3 import ( 4 "fmt" 5 "runtime" 6 "strings" 7 8 _ "embed" 9 10 ignore "github.com/sabhiram/go-gitignore" 11 ) 12 13 //go:embed data/Windows.gitignore 14 var WindowsGitignore []byte 15 16 //go:embed data/macOS.gitignore 17 var macOSGitignore []byte 18 19 //go:embed data/Linux.gitignore 20 var LinuxGitignore []byte 21 22 //go:embed data/common.gitignore 23 var commonGitignore []byte 24 25 func New(overrides ...string) (*ignore.GitIgnore, error) { 26 if len(overrides) > 0 { 27 return ignore.CompileIgnoreLines(overrides...), nil 28 } 29 30 os := runtime.GOOS 31 switch os { 32 case "windows": 33 return ignore.CompileIgnoreLines(format(WindowsGitignore)...), nil 34 case "darwin": 35 return ignore.CompileIgnoreLines(format(macOSGitignore)...), nil 36 case "linux": 37 return ignore.CompileIgnoreLines(format(LinuxGitignore)...), nil 38 default: 39 return &ignore.GitIgnore{}, fmt.Errorf("unknown os %s", os) 40 } 41 } 42 43 func format(b []byte) []string { 44 return append(strings.Split(string(commonGitignore), "\n"), strings.Split(string(b), "\n")...) 45 }