From 8908af67d047c17611028587a3a1cf6ca09b5ac2 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Sun, 8 Nov 2015 17:34:53 -0500 Subject: [PATCH] Update to gobook@5e58e0a92b96bee61856a8ce6e75ed849bd504af --- ch1/server1/main.go | 2 +- ch1/server3/main.go | 17 +---------------- ch11/storage1/storage.go | 4 +++- ch11/storage2/quota_test.go | 5 +---- ch11/storage2/storage.go | 2 -- ch3/printints/main.go | 2 +- ch7/eval/print.go | 11 ++++++----- 7 files changed, 13 insertions(+), 30 deletions(-) diff --git a/ch1/server1/main.go b/ch1/server1/main.go index 0bc7ce0..600e92c 100644 --- a/ch1/server1/main.go +++ b/ch1/server1/main.go @@ -18,7 +18,7 @@ func main() { log.Fatal(http.ListenAndServe("localhost:8000", nil)) } -// handler echoes the Path component of the request URL r. +// handler echoes the Path component of the requested URL. func handler(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "URL.Path = %q\n", r.URL.Path) } diff --git a/ch1/server3/main.go b/ch1/server3/main.go index aa8316c..88c4ad5 100644 --- a/ch1/server3/main.go +++ b/ch1/server3/main.go @@ -2,24 +2,18 @@ // License: https://creativecommons.org/licenses/by-nc-sa/4.0/ // See page 21. -//!+ -// Server3 is a minimal "echo" and counter server. +// Server3 is an "echo" server that displays request parameters. package main import ( "fmt" "log" "net/http" - "sync" ) -var mu sync.Mutex -var count int - func main() { http.HandleFunc("/", handler) - http.HandleFunc("/count", counter) log.Fatal(http.ListenAndServe("localhost:8000", nil)) } @@ -41,12 +35,3 @@ func handler(w http.ResponseWriter, r *http.Request) { } //!-handler - -// counter echoes the number of calls so far. -func counter(w http.ResponseWriter, r *http.Request) { - mu.Lock() - fmt.Fprintf(w, "Count %d", count) - mu.Unlock() -} - -//!- diff --git a/ch11/storage1/storage.go b/ch11/storage1/storage.go index 9c2c81c..ed8982c 100644 --- a/ch11/storage1/storage.go +++ b/ch11/storage1/storage.go @@ -13,7 +13,9 @@ import ( "net/smtp" ) -func bytesInUse(username string) int64 { return 0 /* ... */ } +var usage = make(map[string]int64) + +func bytesInUse(username string) int64 { return usage[username] } // Email sender configuration. // NOTE: never put passwords in source code! diff --git a/ch11/storage2/quota_test.go b/ch11/storage2/quota_test.go index 513a051..2dcd045 100644 --- a/ch11/storage2/quota_test.go +++ b/ch11/storage2/quota_test.go @@ -16,10 +16,7 @@ func TestCheckQuotaNotifiesUser(t *testing.T) { } const user = "joe@example.org" - - // Simulate a 980MB-used condition for this user. - // NOTE: this differs slightly from the printed version. - usage["joe@example.org"] = 980000000 + usage[user] = 980000000 // simulate a 980MB-used condition CheckQuota(user) if notifiedUser == "" && notifiedMsg == "" { diff --git a/ch11/storage2/storage.go b/ch11/storage2/storage.go index e9ca221..f103fbb 100644 --- a/ch11/storage2/storage.go +++ b/ch11/storage2/storage.go @@ -4,7 +4,6 @@ // See page 312. // Package storage is part of a hypothetical cloud storage server. -//!+main package storage import ( @@ -13,7 +12,6 @@ import ( "net/smtp" ) -// NOTE: this differs slightly from the printed version. var usage = make(map[string]int64) func bytesInUse(username string) int64 { return usage[username] } diff --git a/ch3/printints/main.go b/ch3/printints/main.go index 6dfa047..1c875d8 100644 --- a/ch3/printints/main.go +++ b/ch3/printints/main.go @@ -12,7 +12,7 @@ import ( ) //!+ -// intsToString is like fmt.Sprintf(values) but adds commas. +// intsToString is like fmt.Sprint(values) but adds commas. func intsToString(values []int) string { var buf bytes.Buffer buf.WriteByte('[') diff --git a/ch7/eval/print.go b/ch7/eval/print.go index 1d3be26..69bf2db 100644 --- a/ch7/eval/print.go +++ b/ch7/eval/print.go @@ -1,8 +1,6 @@ // Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan. // License: https://creativecommons.org/licenses/by-nc-sa/4.0/ -//+build ignore - package eval import ( @@ -26,19 +24,19 @@ func write(buf *bytes.Buffer, e Expr) { case Var: fmt.Fprintf(buf, "%s", e) - case *unary: + case unary: fmt.Fprintf(buf, "(%c", e.op) write(buf, e.x) buf.WriteByte(')') - case *binary: + case binary: buf.WriteByte('(') write(buf, e.x) fmt.Fprintf(buf, " %c ", e.op) write(buf, e.y) buf.WriteByte(')') - case *call: + case call: fmt.Fprintf(buf, "%s(", e.fn) for i, arg := range e.args { if i > 0 { @@ -47,5 +45,8 @@ func write(buf *bytes.Buffer, e Expr) { write(buf, arg) } buf.WriteByte(')') + + default: + panic(fmt.Sprintf("unknown Expr: %T", e)) } }