|
@@ -19,11 +19,22 @@ type Message struct {
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
|
- // TODO: Create a new bufio.Scanner reading from the standard input.
|
|
|
- // TODO: Create a new json.Encoder writing into the standard output.
|
|
|
- for /* TODO: Iterate over every line in the scanner */ {
|
|
|
- // TODO: Create a new message with the read text.
|
|
|
- // TODO: Encode the message, and check for errors!
|
|
|
+ // Defaults to ScanLines
|
|
|
+ in := bufio.NewScanner(os.Stdin)
|
|
|
+ // in.Split(bufio.ScanLines)
|
|
|
+
|
|
|
+ encoder := json.NewEncoder(os.Stdout)
|
|
|
+
|
|
|
+ for in.Scan() {
|
|
|
+ m := Message{
|
|
|
+ Body:in.Text(),
|
|
|
+ }
|
|
|
+ err := encoder.Encode(m)
|
|
|
+ if err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if err := in.Err(); err != nil {
|
|
|
+ log.Fatal(err)
|
|
|
}
|
|
|
- // TODO: Check for a scan error.
|
|
|
}
|