Output is always the same

I am very new to Golang and have just installed Goland.

My code is simple and looks like this:

package main

import (

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.

How can I fix this issue?

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 :frowning:

@francesc tweeted about a way to find a process running on a specific port in case that helps you out - https://twitter.com/francesc/status/982025296898478080

Kill the process running on port 8080 already and then try :slight_smile:
or maybe you need to stop the http server created via Goland.

1 Like

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

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.