go写一个简单的HTTP服务器


package main
  
import (
        "net/http"
		"fmt"
       )

func main() {
    http.HandleFunc("/",myResponse)
   http.ListenAndServe("127.0.0.1:8888",nil)
}

func myResponse(w http.ResponseWriter,r* http.Request)  {
    w.Write([]byte("<html><center> <font size=\"40\">Hello! I am go service started by Alexander!</font></center></html>"))
	fmt.Println("A client has just visited!")
}


////////////////////////////////////////////////////////////////////////

// package main
 
// import (
//    "fmt"
//    "net/http"
// )
 
// func HelloHandler(w http.ResponseWriter, r *http.Request) {
//    fmt.Fprintf(w, "Hello World")
// }
 
// func main () {
//    http.HandleFunc("/", HelloHandler)
//    http.ListenAndServe(":8080", nil)
// }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM