Goweb – handling static resources


Working with static files

For static files such as CSS and JS in HTML pages, you need to use the following under net / HTTP package
Method to handle

1) Stripprefix function
2) Fileserver function

3) for example:
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("views/static"))))

  • /static/Will match to/static/Development path, when browser requestsindex.htmlIn the page
    style.csS file,staticThe prefix will be replaced withviews/staicAnd then goviews/static/css
    Search in directorystyle.cssfile

Recommended Today

[reading notes] calculation advertising (Part 3)

By logm This article was originally published at https://segmentfault.com/u/logm/articles and is not allowed to be reproduced~ If the mathematical formula in the article cannot be displayed correctly, please refer to: Tips for displaying the mathematical formula correctly This article isComputing advertising (Second Edition)Reading notes. This part introduces the key technology of online advertising, which is […]