-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
63 lines (53 loc) · 1.15 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"log"
"os"
"os/signal"
"syscall"
"time"
"tantalic.com/dropbox"
)
const (
Version = "0.1.1"
)
func main() {
opts, err := optsFromEnv()
if err != nil {
log.Println(err)
os.Exit(1)
}
log.Printf("Starting dropbox-oneway (v%s)\n", Version)
client := dropbox.Client{
AuthorizationToken: opts.DropboxToken,
}
// Creates a channel for new/modified files and background
// goroutine that downloads each file sent to the channel.
fileChan := make(chan dropbox.MetaData)
go func() {
for file := range fileChan {
if file.IsFile() {
go download(client, file, opts.LocalDirectory)
}
}
}()
// Watches for new/modified files in the given directory
// adding them to the channel created above.
err = client.Watch(time.Second*10, dropbox.ListOptions{
Path: opts.DropboxDirectory,
Recursive: true,
}, fileChan)
if err != nil {
log.Printf("Error: %s\n", err.Error())
}
// Wait for exit signal
sigs := make(chan os.Signal, 1)
done := make(chan bool, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
sig := <-sigs
log.Println(sig)
done <- true
}()
<-done
log.Println("exiting")
}