github.com/stevenmatthewt/agent@v3.5.4+incompatible/process/cat.go (about)

     1  package process
     2  
     3  import (
     4  	"bytes"
     5  	"io/ioutil"
     6  	"path/filepath"
     7  
     8  	"github.com/buildkite/agent/logger"
     9  )
    10  
    11  // Replicates how the command line tool `cat` works, but is more verbose about
    12  // what it does
    13  func Cat(path string) string {
    14  	files, err := filepath.Glob(path)
    15  
    16  	if err != nil {
    17  		logger.Debug("Failed to get list of files: %s", path)
    18  
    19  		return ""
    20  	} else {
    21  		var buffer bytes.Buffer
    22  
    23  		for _, file := range files {
    24  			data, err := ioutil.ReadFile(file)
    25  
    26  			if err != nil {
    27  				logger.Debug("Could not read file: %s (%T: %v)", file, err, err)
    28  			} else {
    29  				buffer.WriteString(string(data))
    30  			}
    31  		}
    32  
    33  		return buffer.String()
    34  	}
    35  }