How to map path parameters in golang?

Context

I am trying to build a Go Serverless function with vercel, but my route needs a path parameter.

The Problem

How can I map path parameters in golang with vercel?

Attempts

  1. Given the following folder structure
  • api
    • user
      if i use code like
func GetUser(w http.ResponseWriter, r *http.Request) {
	usr := strings.TrimPrefix(r.URL.Path, "api/user/")
	if cal == "" {
		http.Error(w, "Invalid user", http.StatusBadRequest)
		return
	}
	_, err := w.Write([]byte(cal))
	if err != nil {
		slog.Error("Error answering", err)
	}
}

But I when I make a request to /api/user/1 it returns a 404 (not found)

  1. Same but with [id] directory
  2. Same but with [id].go file

There’s another community post with 404 debugging tips that might be helpful. Please give these solutions a try and let us know how it goes.

A human should be around soon to offer more advice. But you can also get helpful information quickly by asking v0.