強大的Go開發服務器簡單例子

packagemain
import"net/http"
funcSayHello(whttp.ResponseWriter,r*http.Request){
    w.Write([]byte("hello"))
}
funcmain(){
    http.HandleFunc("/hello",SayHello())
    http.ListenAndServe(":1234",nil)
}
listenAndServer進行端口的監聽
handlefunc進行註冊路徑的處理函數
處理函數爲sayhello

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章