2024-02-04 09:45:14 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-06 17:12:29 +01:00
|
|
|
"bufio"
|
2024-02-04 09:45:14 +01:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
var names = []string{}
|
|
|
|
var err error
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
if len(os.Args) < 2 || len(os.Args) > 2 {
|
|
|
|
fmt.Println("Usage: ./file-reader names.txt")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
filePath := os.Args[1]
|
|
|
|
|
2024-02-06 17:12:29 +01:00
|
|
|
file, err := os.Open(filePath)
|
2024-02-04 09:45:14 +01:00
|
|
|
if err != nil {
|
|
|
|
fmt.Print(err)
|
|
|
|
}
|
2024-02-06 17:12:29 +01:00
|
|
|
defer file.Close()
|
2024-02-04 09:45:14 +01:00
|
|
|
|
2024-02-06 17:12:29 +01:00
|
|
|
scanner := bufio.NewScanner(file)
|
|
|
|
for scanner.Scan() {
|
|
|
|
names = append(names, scanner.Text())
|
2024-02-04 09:45:14 +01:00
|
|
|
}
|
2024-02-06 17:12:29 +01:00
|
|
|
|
|
|
|
fmt.Println(names)
|
|
|
|
|
2024-02-04 09:45:14 +01:00
|
|
|
}
|