github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/os/fsi/osfs/20-types.go (about) 1 package osfs 2 3 import ( 4 "os" 5 "runtime" 6 "sort" 7 8 "github.com/pbberlin/tools/os/fsi" 9 ) 10 11 type osFileSys struct { 12 replacePath bool 13 readdirsorter func([]os.FileInfo) 14 } 15 16 func New(options ...func(fsi.FileSystem)) *osFileSys { 17 18 repl := false 19 if runtime.GOOS == "windows" { 20 repl = true 21 } 22 23 o := &osFileSys{} 24 o.replacePath = repl 25 o.readdirsorter = func(fis []os.FileInfo) {} // unchanged 26 27 for _, option := range options { 28 option(o) // apply options over defaults 29 } 30 31 return o 32 } 33 34 // Default sort for ReadDir... is ByNameAsc 35 // We may want to change this; for instance sort byDate 36 func DirSort(srt string) func(fsi.FileSystem) { 37 return func(fs fsi.FileSystem) { 38 fst := fs.(*osFileSys) 39 40 switch srt { 41 case "byDateAsc": 42 fst.readdirsorter = func(fis []os.FileInfo) { sort.Sort(byDateAsc(fis)) } 43 case "byDateDesc": 44 fst.readdirsorter = func(fis []os.FileInfo) { sort.Sort(byDateDesc(fis)) } 45 case "byName": 46 fst.readdirsorter = func(fis []os.FileInfo) {} // unchanged 47 } 48 } 49 }