-2

Created basic web app and it is running on localhost:8080, I have to restart the server on each file change. File changes take affect Ctrl +c (terminate program)and run again go program go run hello.go.

We do not want to terminate program of each file changes. If we do any changes and refresh browser new change take affect like PHP language

EX

First Program


package main

import (
    "fmt"
    "net/http"
)

func helloWorld(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Hello World")
}

func main() {
    http.HandleFunc("/", helloWorld)
    http.ListenAndServe(":8080", nil)
}

Second Program


package main

import (
    "fmt"
    "net/http"
)

func helloWorld(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "Happy Coding")
}

func main() {
    http.HandleFunc("/", helloWorld)
    http.ListenAndServe(":8080", nil)
}

Anyone have a solution to this?

nitin jain
  • 298
  • 6
  • 19

1 Answers1

3

You have to understand that Go & PHP are not the same at all. Go is a statically-typed, COMPILED language -- where PHP is a dynamically-typed, INTERPRETED language.

So using some special third party solution like the one mentioned in the comment above by @AyushGupta is probably your best bet. What you described in your question is the workflow when building services with Go. You compile a binary, run it & repeat when you make changes.

Geoherna
  • 3,523
  • 1
  • 24
  • 39