-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathmain.go
49 lines (42 loc) · 763 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"bufio"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"os"
"os/exec"
)
func main() {
r := gin.Default()
r.StaticFS("/root", http.Dir("/root/"))
r.GET("/d", func(c *gin.Context) {
uu := c.Query("url")
go func(u string) {
fmt.Println(u + " start!!!!")
download(u)
fmt.Println(u + " done!!!!")
}(uu)
c.JSON(200, gin.H{
"out": "ok",
})
})
port := os.Getenv("PORT")
if len(port) == 0 {
port = "8080"
}
r.Run(":" + port)
}
func download(u string) {
cc := "/root/run.sh " + u
cmd := exec.Command("sh", "-c", cc)
stderr, _ := cmd.StderrPipe()
cmd.Start()
scanner := bufio.NewScanner(stderr)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
m := scanner.Text()
fmt.Println(m)
}
cmd.Wait()
}