-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (42 loc) · 1.08 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
package main
import (
"flag"
"github.com/sirupsen/logrus"
"github.com/tjgq/sane"
"github.com/babolivier/scanner/config"
"github.com/babolivier/scanner/http"
"github.com/babolivier/scanner/scanner"
"github.com/babolivier/scanner/webdav"
)
var (
cfgPath = flag.String("c", "config.yaml", "Path to the configuration file")
)
func main() {
// Parse the command-line arguments.
flag.Parse()
// Configure the logger to log the full date.
logrus.SetFormatter(
&logrus.TextFormatter{
TimestampFormat: "2006-02-01 15:04:05.999",
FullTimestamp: true,
},
)
// Parse the configuration file.
cfg, err := config.NewConfig(*cfgPath)
if err != nil {
panic(err)
}
// Instantiate the WebDAV client.
webDAVClient := webdav.NewClient(cfg.WebDAV)
// Instantiate the scanner.
s, err := scanner.NewScanner(cfg.Scanner, webDAVClient)
if err != nil {
panic(err)
}
// Close the SANE connection and release all resources in use by SANE when exiting.
defer sane.Exit()
// Start the HTTP server.
if err = http.ListenAndServe(cfg.HTTP, s, webDAVClient); err != nil {
panic(err)
}
}