Skip to content

Commit 8c60f35

Browse files
committed
move killbrowser in its own package
1 parent 366846c commit 8c60f35

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

killbrowser.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"net/http"
66

7+
"github.com/arduino/arduino-create-agent/killbrowser"
78
"github.com/gin-gonic/gin"
89
)
910

@@ -22,23 +23,23 @@ func killBrowserHandler(c *gin.Context) {
2223
return
2324
}
2425

25-
command, err := findBrowser(data.Process)
26+
command, err := browser.Find(data.Process)
2627

2728
if err != nil {
2829
c.JSON(http.StatusInternalServerError, err.Error())
2930
return
3031
}
3132

3233
if data.Action == "kill" || data.Action == "restart" {
33-
_, err := killBrowser(data.Process)
34+
_, err := browser.Kill(data.Process)
3435
if err != nil {
3536
c.JSON(http.StatusInternalServerError, err.Error())
3637
return
3738
}
3839
}
3940

4041
if data.Action == "restart" {
41-
_, err := startBrowser(command, data.URL)
42+
_, err := browser.Start(command, data.URL)
4243
if err != nil {
4344
c.JSON(http.StatusInternalServerError, err.Error())
4445
return

killbrowser/killbrowser_darwin.go

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package browser
2+
3+
func Find(process string) ([]byte, error) {
4+
return nil, nil
5+
}
6+
7+
func Kill(process string) ([]byte, error) {
8+
return nil, nil
9+
}
10+
11+
func Start(command []byte, url string) ([]byte, error) {
12+
return nil, nil
13+
}

killbrowser_linux.go renamed to killbrowser/killbrowser_linux.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package browser
22

33
import (
44
"os/exec"
@@ -7,20 +7,20 @@ import (
77
"github.com/arduino/arduino-create-agent/utilities"
88
)
99

10-
func findBrowser(process string) ([]byte, error) {
10+
func Find(process string) ([]byte, error) {
1111
ps := exec.Command("ps", "-A", "-o", "command")
1212
grep := exec.Command("grep", process)
1313
head := exec.Command("head", "-n", "1")
1414

1515
return utilities.PipeCommands(ps, grep, head)
1616
}
1717

18-
func killBrowser(process string) ([]byte, error) {
18+
func Kill(process string) ([]byte, error) {
1919
cmd := exec.Command("pkill", "-9", process)
2020
return cmd.Output()
2121
}
2222

23-
func startBrowser(command []byte, url string) ([]byte, error) {
23+
func Start(command []byte, url string) ([]byte, error) {
2424
parts := strings.Split(string(command), " ")
2525
cmd := exec.Command(parts[0], url)
2626
return cmd.Output()
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
package main
1+
package browser
22

33
import "os/exec"
44

5-
func findBrowser(process string) ([]byte, error) {
5+
func Find(process string) ([]byte, error) {
66
return []byte(process), nil
77
}
88

9-
func killBrowser(process string) ([]byte, error) {
9+
func Kill(process string) ([]byte, error) {
1010
cmd := exec.Command("Taskkill", "/F", "/IM", process+".exe")
1111
return cmd.Output()
1212
}
1313

14-
func startBrowser(command []byte, url string) ([]byte, error) {
14+
func Start(command []byte, url string) ([]byte, error) {
1515
cmd := exec.Command("cmd", "/C", "start", string(command), url)
1616
return cmd.Output()
1717
}

killbrowser_darwin.go

-13
This file was deleted.

0 commit comments

Comments
 (0)