title: Serving static css and java script while using parameters in Golang using github.com/julienschmidt/httprouter
body: <p>So I'm trying to serve static css and java script to an html template, but the parameters are hindering my ability to do so. </p>
  
  <p>here's my code </p>
  
  <pre><code>package main
  
  import (
      "net/http"
      "html/template"
      "github.com/julienschmidt/httprouter"
      "fmt"
  )
  
  type PageData struct {
      Chapter int
      Page int
      Source string
  }
  
  func main(){
  
      //I'm using the julienschmidt router because it has parameters that I can use
      //Create a router
      router := httprouter.New()
  
      //Create the route with the parameters
      router.GET("/:chapter/:page",paramHandler)
      //Create the default route last
      router.GET("/",defaultHandler)
  
      //get all of the static files working
      router.ServeFiles("/:chapter/:page/*filepath",http.Dir("/js/"))
  
      //http.Handle("/js/",http.StripPrefix("/js/",http.FileServer(http.Dir("./public/js/"))))
      //http.Handle("/viewjs/",http.StripPrefix("/viewjs/",http.FileServer(http.Dir("./public/viewjs/"))))
  
      //crate a message telling the user which port the server is running on
      fmt.Println("Now serving on port 8080")
      //Start the server on the specified port
      http.ListenAndServe(":8080",router)
  }
  
  func defaultHandler(rw http.ResponseWriter,r *http.Request,p httprouter.Params){
      //Parse the html file
      index := template.Must(template.ParseFiles("public/index.html"))
      chapter := 1
      page := 1
      //Get data from server
      //TODO
  
      //Test Data
      //defaultPage := PageData{Chapter:chapter,Page:page,Source:"http://lokeshdhakar.com/projects/lightbox2/images/image-4.jpg"}
  
      //Send the html file to the browser
      fmt.Printf("\nThe chapter is %d and the page is %d",chapter,page)
      index.Execute(rw,nil)
  }
  
  func paramHandler(rw http.ResponseWriter,r*http.Request,p httprouter.Params){
      index := template.Must(template.ParseFiles("public/index.html"))
      //Get the page parameters
      chapter := p.ByName("chapter")
      page:= p.ByName("page")
  
      //Get data from server
      //TODO
  
      //send the html to the page
      fmt.Printf("\nThe chapter is %s and the page is %s",chapter,page)
      index.Execute(rw,nil)
  }
  </code></pre>
  
  <p>so basically, I want to serve a different image based on the chapter and page variable (That isn't my current problem, but it is the reason I need the url parameters), but the router thinks that the static file path (the one I use to serve js and css) is full of parameters. I tried to just add "/foo/foo/" to the begging of every path in the html, but that didn't work either
  Here's a sample output from the console:</p>
  
  <p>from "/"</p>
  
  <pre><code>The chapter is 1 and the page is 1
  The chapter is viewjs and the page is index.js
  The chapter is viewjs and the page is index.js
  </code></pre>
  
  <p>from "/1/2"</p>
  
  <pre><code>The chapter is 1 and the page is 2
  The chapter is viewjs and the page is index.js
  The chapter is viewjs and the page is index.js
  </code></pre>
  
  <p><a href="https://github.com/mjbaig/WebComicApp" rel="nofollow">here's</a> the repository with all of my files so you can see my project structure. </p>
  
  <p>Thanks!</p>