some-advent-of-code: 0e9ec2ef1a8f4407571888ddee2eee085005a687
1: package main
2:
3: import (
4: "bufio"
5: "fmt"
6: "log"
7: "os"
8: )
9:
10: func main() {
11: if len( os.Args ) < 2 {
12: log.Fatal( "Error: need filepath argument" )
13: }
14: filePath := os.Args[ 1 ]
15: fileLines := readLines( filePath )
16:
17: xxx( fileLines )
18: }
19:
20: func readLines( filepath string ) []string {
21: file, err := os.Open(filepath)
22: if err != nil {
23: log.Fatal(err)
24: }
25:
26: defer file.Close()
27:
28: var lines []string
29:
30: scanner := bufio.NewScanner(file)
31: for scanner.Scan() {
32: lines = append(lines, scanner.Text())
33: }
34:
35: if scanner.Err() != nil {
36: log.Fatal(scanner.Err())
37: }
38: return lines
39: }
40:
41: func xxx( fileLines []string ) {
42: for _, line := range fileLines {
43: if len( line ) < 1 {
44: continue
45: }
46: fmt.Println( line )
47: }
48:
49: fmt.Println( "\tresult" )
50: }
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
Generated by git2html.