34 lines
480 B
Go
34 lines
480 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"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]
|
||
|
|
||
|
names, err := fileReader(filePath)
|
||
|
if err != nil {
|
||
|
fmt.Print(err)
|
||
|
}
|
||
|
fmt.Println(names)
|
||
|
}
|
||
|
|
||
|
func fileReader(path string) (str string, err error) {
|
||
|
b, err := os.ReadFile(path)
|
||
|
if err != nil {
|
||
|
fmt.Print(err)
|
||
|
}
|
||
|
stre := string(b)
|
||
|
return stre, err
|
||
|
}
|