Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add go1.22 "net/http" package’s router #7572

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions go/nethttp/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
framework:
website: https://go.dev/
xuyang2 marked this conversation as resolved.
Show resolved Hide resolved
# https://go.dev/blog/routing-enhancements
version: "1.22"
xuyang2 marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions go/nethttp/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module main

go 1.22
xuyang2 marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions go/nethttp/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
Loading