I am very new to Golang and have just installed Goland.
My code is simple and looks like this:
package main
import (
"fmt"
"net/http"
)
func main() {
http.HandleFunc("/", func (w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello World!")
})
http.ListenAndServe(":8080", nil)
}
If I click on Run ‘go build index.go’, on my browser I see “Hello World!” but I cannot change the code anymore. It stays always the same. It will only works if I change the port to anything else.
What is likely happening is you have an application already running on port 8080, so even though you are making changes to this program, the old one isn’t stopping.
The “simple” solution is to restart your computer and that should stop the other program. The problem is you might run into this issue again, and I’m not sure how you are running your code or how this happened in the first place so I can’t easily help you solve that part
Thank you. Strg + F2 (to stop the process) and Strg + F5 (to rerun ‘go build index.go’) solved my problem. Is there a way to change the shortcut Strg + S? It should do more than just saving the file. It should save the file, stop the process and rerun the file. In this case: 1. Strg + S, 2. Strg + F2, 3. Strg + F5