title: chi.URLParam not working when handler is defined outside main package
body: <p>So I am new to go and I currently try to build a little REST-API using chi (and I love it). Yesterday I run into a problem, that I cannot quite understand.</p>
  <p>In my little test-project I have a <code>main.go</code> file which contains the main function with router instantiation, adding middlewares and starting the server:</p>
  <pre><code>func main() {
      router := chi.NewRouter()
      // Middleware
      router.Use(middleware.RequestID)
      router.Use(middleware.RealIP)
      router.Use(middleware.Logger)
      router.Use(middleware.Recoverer)
      // Routes
      router.Post(&quot;/login&quot;, users.Login)
      router.Post(&quot;/register&quot;, users.Register)
      router.With(users.LoginRequired).Route(&quot;/users&quot;, func(r chi.Router) {
          r.Get(&quot;/{user_id}&quot;, users.GetUser)
      })
      // Start Server
      port := &quot;:8080&quot;
      log.Printf(&quot;Server starting at port %v\n&quot;, port)
      log.Fatal(http.ListenAndServe(port, router))
  }
  </code></pre>
  <p>First the problem didn't exist because I defined all the handler functions within my <code>main.go</code> file and the GetUser-function worked as expected and returned a user from my &quot;Database&quot; (array with 3 users):</p>
  <pre><code>func GetUser(w http.ResponseWriter, r *http.Request) {
      uID := chi.URLParam(r, &quot;user_id&quot;) // Problem when not in main -&gt; uID = &quot;&quot;
      id, err := strconv.Atoi(uID)
      if err != nil {
          log.Printf(&quot;Error while parsing int: %v\n&quot;, err)
          // TODO: return error 400
      }
      user := DataBase[id-1]
      response, err := json.Marshal(user)
  
      if err != nil {
          log.Printf(&quot;Error while marshalling user: %v\n&quot;, err)
      }
      w.Write(response)
  }
  </code></pre>
  <p>As soon as I moved this function out of the <code>main.go</code> file into another package called <code>users</code> the chi.URLParam function returns an empty string and cannot find the URLParam anymore. I read it has something to do with the context, but I cannot wrap my head around that I have to place functions inside the main-file if I want to use the chi functions.</p>
  <p>Am I missing something?</p>
  <p><strong>UPDATE</strong></p>
  <p>As requested I removed everything except the GetUser function. My main.go file currently looks like this:</p>
  <pre><code>package main
  
  import (
      &quot;encoding/json&quot;
      &quot;log&quot;
      &quot;net/http&quot;
      &quot;strconv&quot;
  
      &quot;github.com/MyUserName/MyProjectName/internals/users&quot;
      &quot;github.com/go-chi/chi/v5&quot;
  )
  
  func GetUser(w http.ResponseWriter, r *http.Request) {
  
      id, err := strconv.Atoi(chi.URLParam(r, &quot;user_id&quot;))
      if err != nil {
          log.Printf(&quot;Error while parsing int: %v\n&quot;, err)
          // TODO: return error 400
      }
      log.Printf(&quot;ID=%v, Current Database=%v\n&quot;, id, users.DataBase)
      user := users.DataBase[id-1]
      response, err := json.Marshal(user)
  
      if err != nil {
          log.Printf(&quot;Error while marshalling user: %v\n&quot;, err)
      }
      w.Write(response)
  }
  
  func main() {
      router := chi.NewRouter()
      // Routes
      router.Get(&quot;/users/{user_id}&quot;, GetUser)
      // Start Server
      port := &quot;:8080&quot;
      log.Printf(&quot;Server starting at port %v\n&quot;, port)
      log.Fatal(http.ListenAndServe(port, router))
  }
  </code></pre>
  <p>and my users package looks like this:</p>
  <pre><code>package users
  
  import (
      &quot;encoding/json&quot;
      &quot;log&quot;
      &quot;net/http&quot;
      &quot;strconv&quot;
  
      &quot;github.com/MyUserName/MyProjectName/internals/models&quot;
      &quot;github.com/go-chi/chi&quot;
  )
  
  var (
      DataBase = make([]models.User, 0)
  )
  
  func GetUser(w http.ResponseWriter, r *http.Request) {
  
      id, err := strconv.Atoi(chi.URLParam(r, &quot;user_id&quot;))
      if err != nil {
          log.Printf(&quot;Error while parsing int: %v\n&quot;, err)
          // TODO: return error 400
      }
      log.Printf(&quot;ID=%v, Current Database=%v\n&quot;, id, DataBase)
      user := DataBase[id-1]
      response, err := json.Marshal(user)
  
      if err != nil {
          log.Printf(&quot;Error while marshalling user: %v\n&quot;, err)
      }
      w.Write(response)
  }
  
  func init() {
      initUser := []models.User{
          {
              ID:       1,
              UserName: &quot;john&quot;,
              Password: &quot;doe&quot;,
          },
          {
              ID:       2,
              UserName: &quot;max&quot;,
              Password: &quot;mustermann&quot;,
          },
          {
              ID:       3,
              UserName: &quot;jane&quot;,
              Password: &quot;doe&quot;,
          },
      }
      for _, user := range initUser {
          DataBase = append(DataBase, user)
      }
      log.Println(&quot;Initializing Database&quot;)
  }
  </code></pre>
  <p>When I use the function from the users package it does not work and is still an empty string, if I use the function from the main.go file it works.</p>
  <p><strong>UPDATE</strong></p>
  <p>So apparently I am to stupid to import the same packages twice. In my main file I used &quot;github.com/go-chi/chi/v5&quot; and in my users package I used &quot;github.com/go-chi/chi&quot;. Using the same resolved the issue, thanks a lot</p>