2
모든 웹 요청 전에 전에 함수를 실행하려고합니다.웹 요청 전에 기능 실행
func h1(w http.ResponseWriter, r *http.Request) {
fmt.Pprintf("handler: %s\n", "h1")
}
func h2(w http.ResponseWriter, r *http.Request) {
fmt.Pprintf("handler: %s\n", "h2")
}
func h3(w http.ResponseWriter, r *http.Request) {
fmt.Pprintf("handler: %s\n", "h3")
}
func main() {
http.HandleFunc("/", h1)
http.HandleFunc("/foo", h2)
http.HandleFunc("/bar", h3)
/*
Register a function which is executed before the handlers,
no matter what URL is called.
*/
http.ListenAndServe(":8080", nil)
}
질문 :이 작업을 수행 할 수있는 간단한 방법이 있나요 나는 간단한 웹 서버를 가지고?
매우 우아합니다. 감사! – Kiril