Sfoglia il codice sorgente

Able to read input

Piotr Czajkowski 1 anno fa
parent
commit
e247dcfb9a
1 ha cambiato i file con 27 aggiunte e 0 eliminazioni
  1. 27 0
      06/code.go

+ 27 - 0
06/code.go

@@ -0,0 +1,27 @@
+package main
+
+import (
+	"fmt"
+	"io/ioutil"
+	"log"
+	"os"
+)
+
+func readInput(path string) string {
+	data, err := ioutil.ReadFile(path)
+	if err != nil {
+		log.Fatal(err)
+	}
+
+	return string(data)
+}
+
+func main() {
+	if len(os.Args) < 2 {
+		log.Fatal("You need to specify a file!")
+	}
+
+	filePath := os.Args[1]
+	text := readInput(filePath)
+	fmt.Println(text)
+}