0

I have a CSS file and I am trying to serve it on my Web Server (New with the http package). I have tried

http. (ServeFile, and Handle)

I have also tried serving it as a template, but the issue is that on the bottom of the HTML page, it prints the CSS. What is the proper way of serving the CSS file without it printing the whole CSS file on the bottom of the page?

GoofBall101
  • 308
  • 3
  • 15
  • You can do sonething like this: https://github.com/google/shenzhen-go/blob/master/cmd/shenzhen-go/main.go https://github.com/google/shenzhen-go/blob/master/view/static.go – nk2ge5k Aug 30 '17 at 06:19

2 Answers2

0

You can try this instead.

http.Handle("/", http.FileServer(http.Dir("css/")))

Let me know if it helped you to your problem.

jek
  • 148
  • 1
  • 1
  • 12
  • I get a panic -- panic: http: multiple registrations for /. Would I place this somewhere specifically? – GoofBall101 Aug 30 '17 at 02:51
  • I guess that's an issue due to vendoring. Anyway you can refer to this [issue](https://stackoverflow.com/questions/43601359/how-do-i-serve-css-and-js-in-go-lang). – jek Aug 30 '17 at 02:56
0

I always do this:

http.HandleFunc("/game.css", serveCss)

and this:

func serveCss(w http.ResponseWriter, r *http.Request) {
    http.ServeFile(w, r, "client/game.css")
}

Hope this help

sensorario
  • 20,262
  • 30
  • 97
  • 159