inconshreveable / go-update

Build self-updating Golang programs
Other
2.12k stars 235 forks source link

example handler #40

Open fardok opened 6 years ago

fardok commented 6 years ago

can somebody write any example handler for update?

func updateHandler(w http.ResponseWriter, r *http.Request){

file, err := os.Open("myprogram.exe")

etc....

}

mozey commented 3 years ago

The server could implement a handler as below

func update(w http.ResponseWriter, r *http.Request) {
  http.ServeFile(w, r, filepath.Join("path", "to", "myprogram.exe"))
}
...
http.HandleFunc("/update", update)

Given the doUpdate func as per the README.md, the client might then update itself like this

if *updateFlag {
  err := doUpdate("http://localhost/update")
  if err != nil {
    fmt.Println(err)
    os.Exit(1)
  }
  os.Exit(0)
}