This commit is contained in:
raul 2024-02-02 07:40:01 +00:00
parent 304c8a5bae
commit 50a6d90d8c
2 changed files with 44 additions and 0 deletions

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module gat
go 1.21.6

41
main.go Normal file
View File

@ -0,0 +1,41 @@
package main
import (
"bufio"
"fmt"
"os"
)
// https://golangr.com/file-exists
func main() {
if len(os.Args) < 2 {
fmt.Println("Not enough arguments")
os.Exit(1)
}
for i := 1; i < len(os.Args); i++ {
if _, err := os.Stat(os.Args[i]); err == nil {
reader(os.Args[i])
} else {
fmt.Printf("File does not exist\n")
}
}
}
func reader(file string) {
fil, err := os.Open(file)
if err != nil {
panic(err)
}
defer fil.Close()
scanner := bufio.NewScanner(fil)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
if err := scanner.Err(); err != nil {
fmt.Println(err)
}
}