Just in time processing on a character stream: Difference between revisions

Content added Content deleted
(→‎{{header|Go}}: Corrected 'trans' template.)
(→‎{{header|Go}}: More idiomatic error handling.)
Line 158: Line 158:
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"log"
"strconv"
"strconv"
"strings"
"strings"
Line 166: Line 167:
func getUserInput() []userInput {
func getUserInput() []userInput {
h := "0 18 0 0 0 68 0 1 0 100 0 32 0 114 0 45 0 38 0 26 0 16 0 21 0 17 0 59 0 11 " +
h := "0 18 0 0 0 68 0 1 0 100 0 32 0 114 0 45 0 38 0 26 0 16 0 21 0 17 0 59 0 11 " +
"0 29 0 102 0 0 0 10 0 50 0 39 0 42 0 33 0 50 0 46 0 54 0 76 0 47 0 84 2 28"
"0 29 0 102 0 0 0 10 0 50 0 39 0 42 0 33 0 50 0 46 0 54 0 76 0 47 0 84 2 28"
flds := strings.Fields(h)
flds := strings.Fields(h)
var uis []userInput
var uis []userInput
Line 179: Line 180:
}
}


func decode(fileName string, uis []userInput) {
func decode(fileName string, uis []userInput) error {
text, err := ioutil.ReadFile(fileName)
text, err := ioutil.ReadFile(fileName)
if err != nil {
if err != nil {
panic("Unable to read file")
return err
}
}


Line 221: Line 222:
}
}
fmt.Println()
fmt.Println()
return nil
}
}


func main() {
func main() {
uis := getUserInput()
uis := getUserInput()
decode("theRaven.txt", uis)
err := decode("theRaven.txt", uis)
if err != nil {
log.Fatal(err)
}
}</lang>
}</lang>