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?

1

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

0

You can try this instead.

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

Let me know if it helped you to your problem.

2 Comments

I get a panic -- panic: http: multiple registrations for /. Would I place this somewhere specifically?
I guess that's an issue due to vendoring. Anyway you can refer to this issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.