36 lines
533 B
Go
36 lines
533 B
Go
package file
|
|
|
|
import (
|
|
"bufio"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
// Get the pipe
|
|
func Pipe() []string {
|
|
// Store lines
|
|
var lines []string
|
|
|
|
// Get pipe
|
|
pipe, _ := os.Stdin.Stat()
|
|
|
|
// Piped found
|
|
if (pipe.Mode() & os.ModeCharDevice) == 0 {
|
|
// Create scanner
|
|
scanner := bufio.NewScanner(os.Stdin)
|
|
|
|
// Go through scanner
|
|
for scanner.Scan() {
|
|
// Store line
|
|
line := scanner.Text()
|
|
|
|
// Ignore empty & commented lines
|
|
if line != "" && !strings.HasPrefix(line, "#") {
|
|
lines = append(lines, line)
|
|
}
|
|
}
|
|
}
|
|
|
|
return lines
|
|
}
|