1 package filter 2 3 import ( 4 "os" 5 pathpkg "path" 6 ) 7 8 // FilesWithExtensions returns a filter func that selects files (but not directories) 9 // that have any of the given extensions. For example: 10 // 11 // filter.FilesWithExtensions(".go", ".html") 12 // 13 // Would select both .go and .html files. It would not select any directories. 14 func FilesWithExtensions(exts ...string) Func { 15 return func(path string, fi os.FileInfo) bool { 16 if fi.IsDir() { 17 return false 18 } 19 for _, ext := range exts { 20 if pathpkg.Ext(path) == ext { 21 return true 22 } 23 } 24 return false 25 } 26 } 27