Closed stevenanthonyrevo closed 3 years ago
I can't find "Go/HTTP server" folder
@umairkarel, Thanks for showing interest in this issue. No server folder has been created yet. I'll leave the naming convention up for consideration.
Overall looking for an implementation utilizing Gin or the static function.
A simpler example is calling an "assets" folder within the main package.
router.Static("/assets", "./static")
Let me know if this helps or if you have any further questions, and Happy Hacktoberfest!
@stevenanthonyrevo, it could be also something like this:
fileServer := http.FileServer(http.Dir("./static/"))
router.Handle("/assets/", http.StripPrefix("/static", fileServer))
Happy hacktoberfest (:
Thanks for the code snippet, this is close, @0x471, and Happy Hacktoberfest!
I've tried implementing and received a type error in go.
http.StripPrefix("/static", fileServer) cannot use a string value in argument to router.Handle. (value of type http.Handler)
Please add a PR and I'll merge.
It would be great to see a "/static" directory serving image assets such as logos or photography, even external JS, or CSS.
Feel free to create an implementation that has basic error handling to handle any 404's. This "./static" directory should only serve assets and not give permission access to the root directory of the application.