Update to gobook@5e58e0a92b96bee61856a8ce6e75ed849bd504af
This commit is contained in:
+1
-1
@@ -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)
|
||||
}
|
||||
|
||||
+1
-16
@@ -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()
|
||||
}
|
||||
|
||||
//!-
|
||||
|
||||
Reference in New Issue
Block a user