-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (35 loc) · 782 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"os/signal"
"strconv"
"syscall"
"github.com/RoyXiang/putcallback/rclone"
)
func handleCallback(w http.ResponseWriter, r *http.Request) {
fileId := r.FormValue("file_id")
if fileId != "" {
id, err := strconv.ParseInt(fileId, 10, 64)
if err != nil {
return
}
log.Printf("Callback received (file_id: %d, name: %s)", id, r.FormValue("name"))
go rclone.SendFileIdToWorker(id)
}
_, _ = fmt.Fprint(w, "OK")
}
func main() {
done := make(chan os.Signal, 1)
signal.Notify(done, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
go func() {
http.HandleFunc("/", handleCallback)
log.Fatal(http.ListenAndServe(":1880", nil))
}()
log.Print("Server started on :1880")
rclone.Start()
<-done
rclone.Stop()
}