From 93bac1ad363a7428742d988f7a49c8682b51f5e4 Mon Sep 17 00:00:00 2001 From: Igor V Belousov Date: Tue, 23 Nov 2021 21:29:08 +0300 Subject: [PATCH] Chapter 1 - server1.go --- ch1/server1.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ch1/server1.go diff --git a/ch1/server1.go b/ch1/server1.go new file mode 100644 index 0000000..13c8e9c --- /dev/null +++ b/ch1/server1.go @@ -0,0 +1,18 @@ +// Server1 - минимальный "echo"-сервер +package main + +import ( + "fmt" + "log" + "net/http" +) + +func main() { + http.HandleFunc("/", handler) // Каждый запрос вызывает обработчик + log.Fatal(http.ListenAndServe("localhost:8888", nil)) +} + +// Обработчик возвращает компонент пути из URL запроса. +func handler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "URL.Path = %q\n", r.URL.Path) +}