forked from gogap/go-wkhtmltox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
79 lines (60 loc) · 1.14 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package main
import (
"log"
"os"
"github.com/gogap/config"
"github.com/gogap/go-wkhtmltox/server"
"github.com/urfave/cli"
)
import (
_ "github.com/gogap/go-wkhtmltox/wkhtmltox/fetcher/data"
_ "github.com/gogap/go-wkhtmltox/wkhtmltox/fetcher/http"
)
func main() {
var err error
defer func() {
if err != nil {
log.Printf("[go-wkhtmltox]: %s\n", err.Error())
}
}()
app := cli.NewApp()
app.Usage = "A server for wkhtmltopdf and wkhtmltoimage"
app.Commands = cli.Commands{
cli.Command{
Name: "run",
Usage: "run go-wkhtmltox service",
Action: run,
Flags: []cli.Flag{
cli.StringFlag{
Name: "config,c",
Usage: "config filename",
Value: "app.conf",
},
cli.StringFlag{
Name: "cwd",
Usage: "change work dir",
},
},
},
}
err = app.Run(os.Args)
}
func run(ctx *cli.Context) (err error) {
cwd := ctx.String("cwd")
if len(cwd) != 0 {
err = os.Chdir(cwd)
}
if err != nil {
return
}
configFile := ctx.String("config")
conf := config.NewConfig(
config.ConfigFile(configFile),
)
srv, err := server.New(conf)
if err != nil {
return
}
err = srv.Run()
return
}