0

I'm trying to render external stylesheets. I'm not sure why this is not working:

GO:

func main() {
    http.HandleFunc("/", homeHandler)
    http.HandleFunc("/image/", imageHandler)
    http.Handle("/layout/", http.StripPrefix("/layout/", http.FileServer(http.Dir("layout"))))

    http.ListenAndServe(":8000", nil)
}

Dir structure:

gocode
    layout
        stylesheets
            home.css
    home.html
main.go

HTML:

<link rel="stylesheet" type="text/css" href="/stylesheets/home.css" />

Whats wrong? I followed the example here: Rendering CSS in a Go Web Application

Community
  • 1
  • 1
user3918985
  • 4,278
  • 9
  • 42
  • 63

1 Answers1

3

Your file server is at /layout/, so it should be

<link rel="stylesheet" type="text/css" href="/layout/stylesheets/home.css" />
Ainar-G
  • 34,563
  • 13
  • 93
  • 119