Frederic G. MARAND 4 years ago
parent
commit
ce1d72527c
9 changed files with 50 additions and 6 deletions
  1. 1 0
      .gitignore
  2. 13 0
      .idea/runConfigurations/WG_Step_1.xml
  3. 2 0
      final/go.mod
  4. 2 0
      final/go.sum
  5. 8 0
      go.mod
  6. 4 0
      go.sum
  7. 3 0
      part1/go.mod
  8. 0 0
      part1/go.sum
  9. 17 6
      part1/main.go

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
 .idea/workspace.xml
+wg

+ 13 - 0
.idea/runConfigurations/WG_Step_1.xml

@@ -0,0 +1,13 @@
+<component name="ProjectRunConfigurationManager">
+  <configuration default="false" name="WG Step 1" type="GoApplicationRunConfiguration" factoryName="Go Application">
+    <module name="whispering_gophers" />
+    <working_directory value="$PROJECT_DIR$/part1" />
+    <go_parameters value="-o wg" />
+    <kind value="DIRECTORY" />
+    <filePath value="$PROJECT_DIR$/" />
+    <package value="code.osinet.fr/fgm/whispering_gophers" />
+    <directory value="$PROJECT_DIR$/part1" />
+    <output_directory value="$PROJECT_DIR$/part1" />
+    <method v="2" />
+  </configuration>
+</component>

+ 2 - 0
final/go.mod

@@ -1,3 +1,5 @@
 module code.osinet.fr/fgm/whispering_gophers/final
 
 go 1.12
+
+require code.osinet.fr/fgm/whispering_gophers v0.0.0-20190702093742-2da231b7e53a

+ 2 - 0
final/go.sum

@@ -0,0 +1,2 @@
+code.osinet.fr/fgm/whispering_gophers v0.0.0-20190702093742-2da231b7e53a h1:Abjoon8mgc5Pw8QGMpcGVKUEa4pJUec698DBA/2MmJs=
+code.osinet.fr/fgm/whispering_gophers v0.0.0-20190702093742-2da231b7e53a/go.mod h1:D2yrzQyl6eIIDh4k2cdvIk3tbJ5bQmN/k6sWmt80Vo4=

+ 8 - 0
go.mod

@@ -0,0 +1,8 @@
+module code.osinet.fr/fgm/whispering_gophers
+
+go 1.12
+
+require (
+	github.com/campoy/whispering-gophers v0.0.0-20170829193756-05474ebaae6d
+	github.com/davecgh/go-spew v1.1.1
+)

+ 4 - 0
go.sum

@@ -0,0 +1,4 @@
+github.com/campoy/whispering-gophers v0.0.0-20170829193756-05474ebaae6d h1:O+r1xLjz4nKHUQfuwboUudHoAB4KeGeBPLVlLbb8jQY=
+github.com/campoy/whispering-gophers v0.0.0-20170829193756-05474ebaae6d/go.mod h1:vB9iiwxgXlbPbL378xiG5vWzvDydg/fZLtqAtmaXja4=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

+ 3 - 0
part1/go.mod

@@ -0,0 +1,3 @@
+module code.osinet.fr/fgm/whispering_gophers/part1
+
+go 1.12

+ 0 - 0
part1/go.sum


+ 17 - 6
part1/main.go

@@ -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.
 }