-
Notifications
You must be signed in to change notification settings - Fork 0
/
sftppoller.go
59 lines (48 loc) · 1.27 KB
/
sftppoller.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
package main
import (
"context"
"os"
"os/signal"
log "github.com/Sirupsen/logrus"
"github.com/da4nik/sftppoller/config"
"github.com/da4nik/sftppoller/merger"
"github.com/da4nik/sftppoller/poller"
_ "github.com/joho/godotenv/autoload"
)
var logFile *os.File
var version string
var buildTime string
func initLogger() {
// Setting up logger
log.SetFormatter(&log.TextFormatter{
FullTimestamp: true,
})
log.SetLevel(log.DebugLevel)
log.SetOutput(os.Stdout)
if len(config.LogFileName) > 0 {
var err error
logFile, err = os.OpenFile(config.LogFileName, os.O_WRONLY|os.O_CREATE, 0664)
if err != nil {
log.Warningf("File %s, can't be opened, using STDOUT for logging.", config.LogFileName)
} else {
log.SetOutput(logFile)
}
}
}
func main() {
config.Load()
initLogger()
if version != "" && buildTime != "" {
log.Infof("Starting sftppoller v%s build at %s", version, buildTime)
}
log.Infof("SFTP will be polled every %d seconds.", config.SFTPPollIntervalSeconds)
pollerCtx, pollerCancel := context.WithCancel(context.Background())
poller.Start(pollerCtx)
defer pollerCancel()
mergerCtx, mergerCancel := context.WithCancel(context.Background())
merger.Init(mergerCtx)
defer mergerCancel()
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
<-c
}