Implemented a log parser on GO, at the moment the program takes a path parameter in this format example /var/log/2019/2019-05/2019-05-27/, only parses the current folder and returns the full file paths, I would like to know and how to implement the parser paths to files in the form such as --datastart /var/log/2019/2019-05/2019-05-01/ --dataend/ var/log/2019/2019-05/2019-05-31/, in order to parse a certain range of dates, which are divided into folders.
Sample directory tree
2019
|
-...
-2019-04
|
-2019-04-01
|
-....
-2019-03-30
-2019-05
|
-2019-05-01
|
...
|
-2019-05-31
-...
My function for getting directories files:
func WalkFile(done <- chan struct{},root string)(<-chan string,<-chan error){
paths := make(chan string)
errc := make(chan error,1)
go func() {
defer close(paths)
errc <- filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil{
return err
}
if !info.Mode().IsRegular(){
return nil
}
select {
case paths <- path:
case <-done:
return nil
}
return nil
})
}()
return paths,errc
}