I'm trying to learn go for web programming.
(我正在尝试学习网络编程。)
I came across the http.HandleFunc
function , to which i could provide a callback to handle the web request configured to it. (我遇到了http.HandleFunc
函数,可以向其提供回调以处理配置给它的Web请求。)
My small program looks like the following.
(我的小程序如下所示。)
package main
import (
"fmt"
"log"
"net/http"
"sync"
)
var count int
var mu sync.Mutex
func main() {
var p Point
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe("localhost:8080", nil))
}
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "URL.Path =:%q
", r.URL.Path)
}
Why is the *http.Request in the handler
method a pointer?
(为什么handler
方法中的* http.Request是指针?)
. (。)
I understand that this is how the designed it. (我了解这是如何设计的。)
But I would like to know why they are mandating a pointer instead of a regular value. (但是我想知道为什么他们要使用指针而不是常规值。)
ask by Alan Lal translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…