I started learning Go and I have a problem with processing static files. there is the following:
func main() {
fs := http.FileServer(http.Dir("public"))
http.Handle("/", fs)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
Folder structure:
main.go
public
- index.html
When I started go run main.goand after it changed something in index.htmland started again go run main.go, browsing in the browser did not change. So I searched a little Google and thought that they are in a binary file that compiles, but because it has main.gonot been changed, go will not recompile it. Therefore, I run go run -a main.goto force recompilation, but this does not help.
curl, , - . . , , , public public2 () main.go , .
Go, . - . Ubuntu 16.04 Vagrant.
vagrantfile:
Vagrant.configure("2") do |config|
config.vm.network "forwarded_port", guest: 8080, host: 8080
config.vm.network "forwarded_port", guest: 5432, host: 5432
end
:
2017/11/19 18:25:45 request.RequestURI: /
2017/11/19 18:25:45 request.RemoteAddr: 10.0.2.2:50584
2017/11/19 18:25:45 request.TLS: <nil>
2017/11/19 18:25:45 Request Headers:
2017/11/19 18:25:45 Accept : [text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8]
2017/11/19 18:25:45 Accept-Encoding : [gzip, deflate, br]
2017/11/19 18:25:45 Accept-Language : [en-US,en;q=0.9,ru;q=0.8]
2017/11/19 18:25:45 Cache-Control : [max-age=0]
2017/11/19 18:25:45 Connection : [keep-alive]
2017/11/19 18:25:45 If-Modified-Since : [Sun, 19 Nov 2017 16:24:53 GMT]
2017/11/19 18:25:45 Upgrade-Insecure-Requests : [1]
2017/11/19 18:25:45 User-Agent : [Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36]
:
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 2010
Content-Type: text/html; charset=utf-8
Last-Modified: Sun, 19 Nov 2017 16:24:53 GMT
Date: Sun, 19 Nov 2017 18:25:27 GMT
: vm, , - vm, , .