# Simple Http Client (簡易的Http服務器) ###### tags: `Go` #### Example Create file `project/main.go` ```go package main import ( "fmt" "log" "net/http" ) func homePage(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Home Page") } func wsEndpoint(w http.ResponseWriter, r *http.Request) { fmt.Fprintf(w, "Hello World") } func setupRoutes() { http.HandleFunc("/", homePage) http.HandleFunc("/ws", wsEndpoint) } func main() { fmt.Println("Server opened on port: 80080") setupRoutes() log.Fatal(http.ListenAndServe(":8080", nil)) } ``` #### Execute 執行 在project root執行. ```sh go run main.go ``` Output ``` Server opened on port: 80080 ``` #### Test in browser (在瀏覽器執行) 打開你最愛的瀏覽器並在url欄位上打`localhost:8080` 你會看到`homePage`就表示成功了!