GO: Serve static pages -
I'm trying to display a static page with Go.
Go:
Package main import "net / http" function main () {fs: = http.FileServer (http.Dir ("static / house")) Http: .handle ("/", fs) http.ListenAndServe (": 4747", zero)} directory:
project / stable home Html edit.html project.go When I run it, the web page displays links to edit.html and home.html instead of displaying a static page from home.html is. What am I doing wrong. Is this the best way to serve files? I know that there are other ways like From the HTML / templates package, but I'm not sure what is the difference between each of these methods and when. Thanks!
fancy main () {http.Handle ("/", http.FileServer (Http) .ir ("static")) http.ListenAndServe (": 4747", zero)} You do not need static / home , just Static .
and when you do not have index.html in / static , the directory instead Content appears.
Just change the name of home.html to index.html for a quick fix. .html via http: // localhost: 4747 / and Using edit.html with http: /localhost:747/edit.html .
html / template There is no need to do this, if you only need to serve the files in stable.
But a clean solution depends on what you are actually trying to do.
< / Div>
Comments
Post a Comment