Go

Often a program can be written as one linear path of code that performs a single task and finishes. When this is possible, always choose this option, because this type of program is usually simple to write and maintain. But there are times when executing multiple tasks concurrently has greater benefit. One example is with a web service that can receive multiple requests for data on individual sockets at the same time. Each socket request is unique and can be independently processed from any other. Having the ability to execute requests concurrently can dramatically improve the performance of this type of system. With this in mind, support for concurrency has been built directly into Go's language and runtime.

Here is one example of getting file list of a given directory recursively.

            
            package main
    
            import (
                "fmt"
                "os"
                "path/filepath"
                "regexp"
            )
    
            func main() {
                filePath := "/home/username"
                fileList := GetFileList(filePath)
    
                for i, file := range fileList {
                    fmt.Printf("File #%d: %s\n", i, file)
                }
            }
    
            // GetFileList - get file list of folder
            func GetFileList(filePath string) []string {
    
            var fileList []string
            re, _ := regexp.Compile("^.*\\.(go)$")
    
            err := filepath.Walk(filePath, func(path string, f os.FileInfo, err error) error {
                if re.MatchString(path) {
                    fileList = append(fileList, path)
                }
                return nil
                })
    
            if err != nil {
                panic(err)
            }
                return fileList
            }