Update to gobook@5e58e0a92b96bee61856a8ce6e75ed849bd504af
This commit is contained in:
parent
8eb326f5e8
commit
8908af67d0
@ -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)
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
//!-
|
||||
|
@ -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!
|
||||
|
@ -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 == "" {
|
||||
|
@ -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] }
|
||||
|
@ -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('[')
|
||||
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user