-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.go
More file actions
61 lines (51 loc) · 1.36 KB
/
Main.go
File metadata and controls
61 lines (51 loc) · 1.36 KB
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
package main
import (
"encoding/json"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"os"
"strings"
)
func main() {
var configPath, logPath string
var enableDebug bool
flag.StringVar(&configPath, "c", "config.json", "Absolute path to configuration file")
flag.StringVar(&logPath, "l", "default.log", "Absolute path to store log file, with filename")
flag.BoolVar(&enableDebug, "d", false, "Use this to allow printing to console all information")
flag.Parse()
if !enableDebug {
handleErrorOutput(logPath)
}
log.Println("PikaFileSync is starting...")
data, err := ioutil.ReadFile(configPath)
if err != nil {
fmt.Println("File reading error", err)
return
}
configContent := string(data)
config := json.NewDecoder(strings.NewReader(configContent))
var c Config
if err := config.Decode(&c); err == io.EOF {
return
} else if err != nil {
log.Fatal(err)
}
// Initialize PikaCloud handler
pikaCloudHandler := NewPikaCloudHandler(c.PikaCloud)
if pikaCloudHandler.IsEnabled() {
log.Println("PikaCloud integration enabled")
} else {
log.Println("PikaCloud integration disabled")
}
StartFWatchWithPikaCloud(c.Folders, c.Dst, c.WorkingDirectory, pikaCloudHandler)
}
func handleErrorOutput(outPath string) {
f, err := os.OpenFile(outPath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("error opening file: %v", err)
}
log.SetOutput(f)
}