html – How to use static file in Golang?

Using this file structure and code, I’m trying to make the CSS file work, but it doesn’t include the CSS style when I run the code. I do not know why? Although I searched online and used the answers already given, nothing worked.

 - controllers
 - models
 - views
     - static
          - main.css
     - templates
          - home.html


    <link rel="stylesheet" href="../static/main.css">


fun main(){
    http.HandleFunc("/", controllers.Home)
    http.Handle("/views/", http.StripPrefix("/views/static/", http.FileServer(http.Dir("views/static"))))
    http.ListenAndServe(":4000", nil);

Leave a Reply

Your email address will not be published.