github.com/metux/go-metabuild@v0.0.0-20240118143255-d9ed5ab697f9/util/fileutil/read.go (about)

     1  package fileutil
     2  
     3  import (
     4  	"io/ioutil"
     5  	"path/filepath"
     6  	"strings"
     7  
     8  	"github.com/metux/go-metabuild/util"
     9  )
    10  
    11  func ReadLines(fn string) []string {
    12  	bytesRead, _ := ioutil.ReadFile(fn)
    13  	fileContent := string(bytesRead)
    14  	return strings.Split(fileContent, "\n")
    15  }
    16  
    17  func ReadLinesGlob(glob string) ([]string, error) {
    18  	lines := []string{}
    19  
    20  	files, err := filepath.Glob(glob)
    21  	if err == nil {
    22  		for _, ent := range files {
    23  			lines = append(lines, ReadLines(ent)...)
    24  		}
    25  	}
    26  
    27  	return lines, err
    28  }
    29  
    30  func ReadLinesGlobUniq(glob string) ([]string, error) {
    31  	lines, err := ReadLinesGlob(glob)
    32  	return util.Uniq(lines), err
    33  }