mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 12:32:21 +00:00
24 lines
552 B
Go
Executable File
24 lines
552 B
Go
Executable File
// Copyright © 2017 ChaiShushan <chaishushan{AT}gmail.com>.
|
|
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
func main() {
|
|
fmt.Println("Please visit http://127.0.0.1:12345/")
|
|
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
|
s := fmt.Sprintf("你好, 世界! -- Time: %s", time.Now().String())
|
|
fmt.Fprintf(w, "%v\n", s)
|
|
log.Printf("%v\n", s)
|
|
})
|
|
if err := http.ListenAndServe(":12345", nil); err != nil {
|
|
log.Fatal("ListenAndServe: ", err)
|
|
}
|
|
}
|