I have had the same problem recently and also asked the question here : Serving static (css) files
In my case the problem was that I wasn’t running the main.go from the right directory path. Read the post maybe it will help
You can check if Go an find your css files with this function below. I have left in my own comments to clarify.
// With this fucntion I can check if my filepath is working for serving static files such as CSS or Templates etc
// IMPORTANT:I failed to add static files because Go will use the current Directory you are in as the App's ROOT.
// If I run main.go from GolangBlog, the root is/Users/jorn/Documents/Golang/src/github.com/jschalkwijk/GolangBlog
// If I run it from jschalkwijk (my github folder)
_, err := os.Stat(filepath.Join(".", "YourPathToCSSFolder/css", "style.css"))
checkErr(err)
This is working for me, also with Gorrila:
As I understand it, you are telling to strip /css/ if it is there, and then load the file from a specified folder.
r.PathPrefix("/css/").Handler(http.StripPrefix("/css/",http.FileServer(http.Dir("./YourWebAppFolder/static/css/"))))
HTML:
<link href="/css/style.css" type="text/css" rel="stylesheet"/>
Hope this helps, it got me really frustrated!