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
- Given the following folder structure
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)
- Same but with [id] directory
- Same but with [id].go file
system
(system)
2
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.