golang-exercises/golangr/file-reader/main.go

34 lines
480 B
Go
Raw Normal View History

2024-02-04 09:45:14 +01:00
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
}