mirror of
https://github.com/tenox7/wrp.git
synced 2024-05-28 22:41:36 +00:00
shutdown function via /halt url
This commit is contained in:
parent
57a107aa69
commit
546e686cbc
11
wrp.go
11
wrp.go
|
@ -18,6 +18,7 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
|
@ -61,6 +62,15 @@ func imgServer(out http.ResponseWriter, req *http.Request) {
|
|||
out.Write(gifbuf.Bytes())
|
||||
}
|
||||
|
||||
func haltServer(out http.ResponseWriter, req *http.Request) {
|
||||
log.Printf("%s Shutdown request received [%s]\n", req.RemoteAddr, req.URL.Path)
|
||||
out.Header().Set("Content-Type", "text/plain")
|
||||
fmt.Fprintf(out, "WRP Shutdown")
|
||||
out.(http.Flusher).Flush()
|
||||
cancel()
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func capture(gourl string, out http.ResponseWriter) {
|
||||
var nodes []*cdp.Node
|
||||
ctxx := chromedp.FromContext(ctx)
|
||||
|
@ -122,6 +132,7 @@ func main() {
|
|||
http.HandleFunc("/", pageServer)
|
||||
http.HandleFunc("/wrp.gif", imgServer)
|
||||
http.HandleFunc("/favicon.ico", http.NotFound)
|
||||
http.HandleFunc("/halt", haltServer)
|
||||
log.Printf("Starting http server on %s\n", addr)
|
||||
http.ListenAndServe(addr, nil)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user