Run golang app as background program.
go get github.com/Baozisoftware/GoldenDaemon
package main
import (
"github.com/Baozisoftware/GoldenDaemon"
"flag"
"net/http"
)
func main() {
GoldenDaemon.RegisterTrigger("d", "-restarted")
re := flag.Bool("restarted", false, "test")
flag.Parse()
mux := http.NewServeMux()
mux.HandleFunc("/", func(rw http.ResponseWriter, req *http.Request) {
data := []byte("Hello,世界!")
if *re {
data = append(data, []byte("\n(Restarted)")...)
}
rw.Write(data)
})
http.ListenAndServe(":8080", mux)
}
Precautions
- Avoid using loop output or get input code, otherwise it will make CPU occupancy high;
- For triggering parameters, do not need to add "-"
example.exe
example.exe -d