File: main.go

package info (click to toggle)
golang-github-go-chi-chi 5.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid
  • size: 664 kB
  • sloc: makefile: 19
file content (25 lines) | stat: -rw-r--r-- 550 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package main

import (
	"fmt"
	"net/http"

	"github.com/go-chi/chi/v5"
)

func main() {
	r := chi.NewRouter()

	// Registering a handler that retrieves a path parameter using PathValue
	r.Get("/users/{userID}", pathValueHandler)

	http.ListenAndServe(":3333", r)
}

// pathValueHandler retrieves a URL parameter using PathValue and writes it to the response.
func pathValueHandler(w http.ResponseWriter, r *http.Request) {
	userID := r.PathValue("userID")

	// Respond with the extracted userID
	w.Write([]byte(fmt.Sprintf("User ID: %s", userID)))
}