mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 04:48:29 +08:00
fix: coding style and file format for chapter 11, 12, 13, 14 and 15.
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
// webhello2.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func helloHandler(w http.ResponseWriter, r *http.Request) {
|
||||
remPartOfURL := r.URL.Path[len("/hello/"):] //get everything after the /hello/ part of the URL
|
||||
fmt.Fprintf(w, "Hello %s!", remPartOfURL)
|
||||
}
|
||||
|
||||
func shouthelloHandler(w http.ResponseWriter, r *http.Request) {
|
||||
remPartOfURL := r.URL.Path[len("/shouthello/"):] //get everything after the /shouthello/ part of the URL
|
||||
fmt.Fprintf(w, "Hello %s!", strings.ToUpper(remPartOfURL))
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/hello/", helloHandler)
|
||||
http.HandleFunc("/shouthello/", shouthelloHandler)
|
||||
http.ListenAndServe("localhost:9999", nil)
|
||||
}
|
||||
// webhello2.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func helloHandler(w http.ResponseWriter, r *http.Request) {
|
||||
remPartOfURL := r.URL.Path[len("/hello/"):] //get everything after the /hello/ part of the URL
|
||||
fmt.Fprintf(w, "Hello %s!", remPartOfURL)
|
||||
}
|
||||
|
||||
func shouthelloHandler(w http.ResponseWriter, r *http.Request) {
|
||||
remPartOfURL := r.URL.Path[len("/shouthello/"):] //get everything after the /shouthello/ part of the URL
|
||||
fmt.Fprintf(w, "Hello %s!", strings.ToUpper(remPartOfURL))
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/hello/", helloHandler)
|
||||
http.HandleFunc("/shouthello/", shouthelloHandler)
|
||||
http.ListenAndServe("localhost:9999", nil)
|
||||
}
|
||||
|
Reference in New Issue
Block a user