From 904c01a09867b3253517e1543fe58796de473634 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 9 Mar 2020 12:30:21 +0200 Subject: [PATCH 1/6] Add error check to time-parsing --- .../time-formatting-parsing.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/time-formatting-parsing/time-formatting-parsing.go b/examples/time-formatting-parsing/time-formatting-parsing.go index 2968c3c..34da49b 100644 --- a/examples/time-formatting-parsing/time-formatting-parsing.go +++ b/examples/time-formatting-parsing/time-formatting-parsing.go @@ -18,9 +18,12 @@ func main() { p(t.Format(time.RFC3339)) // Time parsing uses the same layout values as `Format`. - t1, e := time.Parse( + t1, err := time.Parse( time.RFC3339, "2012-11-01T22:08:41+00:00") + if err != nil { + panic(err) + } p(t1) // `Format` and `Parse` use example-based layouts. Usually @@ -34,7 +37,10 @@ func main() { p(t.Format("Mon Jan _2 15:04:05 2006")) p(t.Format("2006-01-02T15:04:05.999999-07:00")) form := "3 04 PM" - t2, e := time.Parse(form, "8 41 PM") + t2, err := time.Parse(form, "8 41 PM") + if err != nil { + panic(err) + } p(t2) // For purely numeric representations you can also @@ -47,6 +53,6 @@ func main() { // `Parse` will return an error on malformed input // explaining the parsing problem. ansic := "Mon Jan _2 15:04:05 2006" - _, e = time.Parse(ansic, "8:41PM") + _, e := time.Parse(ansic, "8:41PM") p(e) } From 7311e83283c382d4c8f935c7de0d3a751c261633 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 9 Mar 2020 12:32:57 +0200 Subject: [PATCH 2/6] Add error check to writing file --- examples/writing-files/writing-files.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/writing-files/writing-files.go b/examples/writing-files/writing-files.go index 82275ce..ef8bd06 100644 --- a/examples/writing-files/writing-files.go +++ b/examples/writing-files/writing-files.go @@ -40,6 +40,7 @@ func main() { // A `WriteString` is also available. n3, err := f.WriteString("writes\n") + check(err) fmt.Printf("wrote %d bytes\n", n3) // Issue a `Sync` to flush writes to stable storage. @@ -49,6 +50,7 @@ func main() { // to the buffered readers we saw earlier. w := bufio.NewWriter(f) n4, err := w.WriteString("buffered\n") + check(err) fmt.Printf("wrote %d bytes\n", n4) // Use `Flush` to ensure all buffered operations have From 5f6871027fadcdb94132439edd7afe00ee00df12 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 9 Mar 2020 12:35:41 +0200 Subject: [PATCH 3/6] Add error check to generate go --- tools/generate.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/generate.go b/tools/generate.go index 04d2e92..ad6af0f 100644 --- a/tools/generate.go +++ b/tools/generate.go @@ -153,11 +153,10 @@ func resetURLHashFile(codehash, code, sourcePath string) string { } payload := strings.NewReader(code) resp, err := http.Post("https://play.golang.org/share", "text/plain", payload) - if err != nil { - panic(err) - } + check(err) defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) + check(err) urlkey := string(body) data := fmt.Sprintf("%s\n%s\n", codehash, urlkey) ioutil.WriteFile(sourcePath, []byte(data), 0644) From 6c1f33628b2231ee7d8d6058cacbd2f464f0d311 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 9 Mar 2020 12:36:29 +0200 Subject: [PATCH 4/6] Add error check to temporary files --- .../temporary-files-and-directories.go | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/temporary-files-and-directories/temporary-files-and-directories.go b/examples/temporary-files-and-directories/temporary-files-and-directories.go index abed14e..c41d230 100644 --- a/examples/temporary-files-and-directories/temporary-files-and-directories.go +++ b/examples/temporary-files-and-directories/temporary-files-and-directories.go @@ -53,6 +53,7 @@ func main() { // `TempFile`'s, but it returns a directory *name* // rather than an open file. dname, err := ioutil.TempDir("", "sampledir") + check(err) fmt.Println("Temp dir name:", dname) defer os.RemoveAll(dname) From ebd652c4f443dcb70d01355980a15e81b977a940 Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 9 Mar 2020 14:41:18 +0200 Subject: [PATCH 5/6] Revert "Add error check to time-parsing" This reverts commit 904c01a09867b3253517e1543fe58796de473634. --- .../time-formatting-parsing.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/examples/time-formatting-parsing/time-formatting-parsing.go b/examples/time-formatting-parsing/time-formatting-parsing.go index 34da49b..2968c3c 100644 --- a/examples/time-formatting-parsing/time-formatting-parsing.go +++ b/examples/time-formatting-parsing/time-formatting-parsing.go @@ -18,12 +18,9 @@ func main() { p(t.Format(time.RFC3339)) // Time parsing uses the same layout values as `Format`. - t1, err := time.Parse( + t1, e := time.Parse( time.RFC3339, "2012-11-01T22:08:41+00:00") - if err != nil { - panic(err) - } p(t1) // `Format` and `Parse` use example-based layouts. Usually @@ -37,10 +34,7 @@ func main() { p(t.Format("Mon Jan _2 15:04:05 2006")) p(t.Format("2006-01-02T15:04:05.999999-07:00")) form := "3 04 PM" - t2, err := time.Parse(form, "8 41 PM") - if err != nil { - panic(err) - } + t2, e := time.Parse(form, "8 41 PM") p(t2) // For purely numeric representations you can also @@ -53,6 +47,6 @@ func main() { // `Parse` will return an error on malformed input // explaining the parsing problem. ansic := "Mon Jan _2 15:04:05 2006" - _, e := time.Parse(ansic, "8:41PM") + _, e = time.Parse(ansic, "8:41PM") p(e) } From bac19fd5d16f1f5634df1d65e71a9cdf6903c16a Mon Sep 17 00:00:00 2001 From: andrew Date: Mon, 9 Mar 2020 14:51:16 +0200 Subject: [PATCH 6/6] HTML changes --- .../temporary-files-and-directories.hash | 4 ++-- examples/writing-files/writing-files.hash | 4 ++-- public/temporary-files-and-directories | 5 +++-- public/writing-files | 6 ++++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/temporary-files-and-directories/temporary-files-and-directories.hash b/examples/temporary-files-and-directories/temporary-files-and-directories.hash index ebe1eeb..cf6faa7 100644 --- a/examples/temporary-files-and-directories/temporary-files-and-directories.hash +++ b/examples/temporary-files-and-directories/temporary-files-and-directories.hash @@ -1,2 +1,2 @@ -371689e72c46daa43eefbd9b9f4eaa3c490e7fd2 -yKWE4QTsYQr +cc4755e23cb4ba3c0e0ef5554ec9e9477372422a +nMpjCsALS6P diff --git a/examples/writing-files/writing-files.hash b/examples/writing-files/writing-files.hash index 3d09d10..1513200 100644 --- a/examples/writing-files/writing-files.hash +++ b/examples/writing-files/writing-files.hash @@ -1,2 +1,2 @@ -d4f19bc0168674b17551bbf55bab7af989452d0e -8kx-qYUXBpA +314a0074840e22b328b6412130c17b9bea53c9c9 +fQ7sd4gXv0F diff --git a/public/temporary-files-and-directories b/public/temporary-files-and-directories index 3919f36..c6f46d3 100644 --- a/public/temporary-files-and-directories +++ b/public/temporary-files-and-directories @@ -45,7 +45,7 @@ time.

- +
package main
 
@@ -175,6 +175,7 @@ rather than an open file.

    dname, err := ioutil.TempDir("", "sampledir")
+    check(err)
     fmt.Println("Temp dir name:", dname)
 
@@ -241,7 +242,7 @@ prefixing them with our temporary directory.

diff --git a/public/writing-files b/public/writing-files index 49214e1..3b20793 100644 --- a/public/writing-files +++ b/public/writing-files @@ -42,7 +42,7 @@ ones we saw earlier for reading.

- +
package main
 
@@ -162,6 +162,7 @@ after opening a file.

    n3, err := f.WriteString("writes\n")
+    check(err)
     fmt.Printf("wrote %d bytes\n", n3)
 
@@ -191,6 +192,7 @@ to the buffered readers we saw earlier.

    w := bufio.NewWriter(f)
     n4, err := w.WriteString("buffered\n")
+    check(err)
     fmt.Printf("wrote %d bytes\n", n4)
 
@@ -287,7 +289,7 @@ we’ve just seen to the stdin and stdout streams.