1234567891011121314151617181920212223242526272829303132333435 |
- package main
- import (
- "os"
- "log"
- "encoding/json"
- "bufio"
- )
- type Message struct {
- Body string
- }
- func main() {
- // TODO: Create a new bufio.Scanner reading from the standard input.
- s := bufio.NewScanner(os.Stdin)
- // TODO: Create a new json.Encoder writing into the standard output.
- e := json.NewEncoder(os.Stdout)
- /* TODO: Iterate over every line in the scanner */
- for s.Scan() {
- // TODO: Create a new message with the read text.
- // TODO: Encode the message, and check for errors!
- err := e.Encode(Message{Body: s.Text()})
- if err != nil {
- log.Fatal(err)
- }
- }
- // TODO: Check for a scan error.
- if err := s.Err(); err != nil {
- log.Fatal(err)
- }
- }
|