title: Serve static files with golang
body: <p>I'm trying to develop a simple web application but I'mhaving problem with serving my static files.</p>
  
  <p>The file structure is:</p>
  
  <ul>
  <li>main</li>
  </ul>
  
  <p>--main.go</p>
  
  <p>-serve</p>
  
  <p>--listenAndServe.go</p>
  
  <p>--templates</p>
  
  <p>---login.html</p>
  
  <p>---assets</p>
  
  <p>----css</p>
  
  <p>----fonts</p>
  
  <p>----js</p>
  
  <p>my code is this:</p>
  
  <pre><code>    import (
          "log"
          "net/http"
          "time"
  
          "github.com/gorilla/mux"
      )
  
      var (
          router = mux.NewRouter()
      )
  
      func (c *Conn) ListenAndServe() {
          fs := http.FileServer(http.Dir("./templates/assets"))
          http.Handle("/assets/", http.StripPrefix("/assets/", fs))
          router.HandleFunc("/", c.IndexPageHandler)
          router.HandleFunc("/login.html", c.LoginPageHandler)
          log.Println("Listening...")
          http.Handle("/", router)
          muxWithMiddlewares := http.TimeoutHandler(router, time.Minute*30, 
          "Timeout!")
           http.ListenAndServe(":8080", muxWithMiddlewares)
        }
  </code></pre>
  
  <p>But for some reason when I run it from main.go it serves the html but not the assets. I would really apreciate some tips. Thanks!</p>