mirror of
https://github.com/gopl-zh/gopl-zh.github.com.git
synced 2024-12-24 13:58:57 +00:00
27 lines
541 B
Go
27 lines
541 B
Go
|
// Copyright © 2016 Alan A. A. Donovan & Brian W. Kernighan.
|
||
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||
|
|
||
|
// See page 19.
|
||
|
//!+
|
||
|
|
||
|
// Server1 is a minimal "echo" server.
|
||
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
http.HandleFunc("/", handler) // each request calls handler
|
||
|
log.Fatal(http.ListenAndServe("localhost:8000", nil))
|
||
|
}
|
||
|
|
||
|
// 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)
|
||
|
}
|
||
|
|
||
|
//!-
|