From 6bacc5c2b6629b6ff2d0e1ab7f32dc1a32669863 Mon Sep 17 00:00:00 2001 From: Eoghan Conlon Date: Fri, 23 Aug 2024 12:16:04 +0100 Subject: [PATCH] Working file parser implemented Signed-off-by: Eoghan Conlon --- .gitignore | 3 ++- src/Helpers.go | 23 +++++++++++++++++++++++ src/main.go | 5 ++++- 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 src/Helpers.go diff --git a/.gitignore b/.gitignore index 62c8935..0ba068a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.idea/ \ No newline at end of file +.idea/ +input/ \ No newline at end of file diff --git a/src/Helpers.go b/src/Helpers.go new file mode 100644 index 0000000..c4eafe0 --- /dev/null +++ b/src/Helpers.go @@ -0,0 +1,23 @@ +package main + +import ( + "bufio" + "log" + "os" +) + +func FileParse(path string) []string { + oFile, err := os.Open(path) + if err != nil { + log.Fatal(err) + } + defer oFile.Close() + + rValue := make([]string, 0) + + scanner := bufio.NewScanner(oFile) + for scanner.Scan() { + rValue = append(rValue, scanner.Text()) + } + return rValue +} diff --git a/src/main.go b/src/main.go index 91e7378..30f9cb1 100644 --- a/src/main.go +++ b/src/main.go @@ -3,5 +3,8 @@ package main import "fmt" func main() { - fmt.Println("Hello World") + input := FileParse("input/test.txt") + for _, s := range input { + fmt.Println(s) + } }