Skip to content

Commit 797caa8

Browse files
committed
Debug informations
1 parent 2ba1652 commit 797caa8

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

killbrowser.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ func killBrowserHandler(c *gin.Context) {
2525
command, err := findBrowser(data.Process)
2626

2727
if err != nil {
28-
c.JSON(http.StatusInternalServerError, err.Error())
28+
c.JSON(http.StatusInternalServerError, gin.H{"when": "find", "err": err.Error()})
2929
return
3030
}
3131

3232
if data.Action == "kill" || data.Action == "restart" {
3333
_, err := killBrowser(data.Process)
3434
if err != nil {
35-
c.JSON(http.StatusInternalServerError, err.Error())
35+
c.JSON(http.StatusInternalServerError, gin.H{"when": "kill", "err": err.Error()})
3636
return
3737
}
3838
}
3939

4040
if data.Action == "restart" {
4141
_, err := startBrowser(command, data.URL)
4242
if err != nil {
43-
c.JSON(http.StatusInternalServerError, err.Error())
43+
c.JSON(http.StatusInternalServerError, gin.H{"when": "start", "err": err.Error()})
4444
return
4545
}
4646
}

killbrowser_linux.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"log"
45
"os/exec"
56
"strings"
67
)
@@ -10,16 +11,33 @@ func findBrowser(process string) ([]byte, error) {
1011
grep := exec.Command("grep", process)
1112
head := exec.Command("head", "-n", "1")
1213

14+
log.Println("ps command:")
15+
log.Printf("%+v", ps)
16+
17+
log.Println("grep command:")
18+
log.Printf("%+v", grep)
19+
20+
log.Println("head command:")
21+
log.Printf("%+v", head)
22+
1323
return pipe_commands(ps, grep, head)
1424
}
1525

1626
func killBrowser(process string) ([]byte, error) {
1727
cmd := exec.Command("pkill", "-9", process)
28+
29+
log.Println("kill command:")
30+
log.Printf("%+v", cmd)
31+
1832
return cmd.Output()
1933
}
2034

2135
func startBrowser(command []byte, url string) ([]byte, error) {
2236
parts := strings.Split(string(command), " ")
2337
cmd := exec.Command(parts[0], url)
38+
39+
log.Println("start command:")
40+
log.Printf("%+v", cmd)
41+
2442
return cmd.Output()
2543
}

0 commit comments

Comments
 (0)