-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
executable file
·59 lines (50 loc) · 1.25 KB
/
main.go
File metadata and controls
executable file
·59 lines (50 loc) · 1.25 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
package main
import (
"backup/cfg"
"backup/logger"
"backup/routes"
"backup/rsync"
"flag"
"github.com/gin-gonic/gin"
)
type Server struct {
router *gin.Engine
conf *cfg.Config
rsyncExecutor *rsync.Executor
}
func (server *Server) init() {
gin.SetMode(gin.ReleaseMode)
server.router = gin.Default()
var router = routes.Loader{}
for _, route := range router.Load(server.conf, server.rsyncExecutor) {
route.Route(server.router)
}
}
// main starts the rsync scheduler and api router, you need to specify a port, or it will default to 8462.
// EX: ./backup -p 8888
func main() {
var port = flag.String("p", "8462", "Service port")
var config = flag.String("c", "config/config.json", "Config file path")
flag.Parse()
log := logger.NewLogger("AUTO_BACKUP")
conf, err := cfg.NewConfig(*config, log)
if err != nil {
log.Critical("IO Error!")
log.Critical(err.Error())
return
}
// Start the rsync scheduler.
rsyncExecutor := rsync.NewExecutor()
rsyncExecutor.Start()
server := Server{
conf: conf,
rsyncExecutor: rsyncExecutor,
}
server.init()
log.Info("Starting 0.0.0.0:%s http service", *port)
// Start the api router.
err = server.router.Run("0.0.0.0:" + *port)
if err != nil {
log.Critical(err.Error())
}
}