From f8ca9165b1dd673a2144da4999a44c32f3ebab48 Mon Sep 17 00:00:00 2001 From: xuyang2 Date: Tue, 2 Jul 2024 20:42:29 +0800 Subject: [PATCH] =?UTF-8?q?Add=20go1.22=20"net/http"=20package=E2=80=99s?= =?UTF-8?q?=20router=20#7571?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go/nethttp/config.yaml | 4 ++++ go/nethttp/go.mod | 3 +++ go/nethttp/main.go | 24 ++++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 go/nethttp/config.yaml create mode 100644 go/nethttp/go.mod create mode 100644 go/nethttp/main.go diff --git a/go/nethttp/config.yaml b/go/nethttp/config.yaml new file mode 100644 index 00000000000..0e8a2a0f337 --- /dev/null +++ b/go/nethttp/config.yaml @@ -0,0 +1,4 @@ +framework: + website: https://go.dev/ + # https://go.dev/blog/routing-enhancements + version: "1.22" diff --git a/go/nethttp/go.mod b/go/nethttp/go.mod new file mode 100644 index 00000000000..906a5706c7e --- /dev/null +++ b/go/nethttp/go.mod @@ -0,0 +1,3 @@ +module main + +go 1.22 diff --git a/go/nethttp/main.go b/go/nethttp/main.go new file mode 100644 index 00000000000..ecad704884d --- /dev/null +++ b/go/nethttp/main.go @@ -0,0 +1,24 @@ +package main + +import ( + "net/http" +) + +func main() { + mux := http.NewServeMux() + + mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("")) + }) + + mux.HandleFunc("GET /user/{name}", func(w http.ResponseWriter, r *http.Request) { + name := r.PathValue("name") + w.Write([]byte(name)) + }) + + mux.HandleFunc("POST /user", func(w http.ResponseWriter, r *http.Request) { + w.Write([]byte("")) + }) + + http.ListenAndServe(":3000", mux) +}