-
Notifications
You must be signed in to change notification settings - Fork 0
/
web_command.go
55 lines (47 loc) · 1.27 KB
/
web_command.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
package main
import (
"fmt"
"time"
"github.com/urfave/cli/v2"
"github.com/vshn/odootools/pkg/odoo"
"github.com/vshn/odootools/pkg/timesheet"
"github.com/vshn/odootools/pkg/web"
)
func RunWebServer(cli *cli.Context) error {
loc, err := time.LoadLocation(cli.String(newDefaultTimezoneFlag().Name))
if err != nil {
return fmt.Errorf("cannot load timezone: %w", err)
}
timesheet.DefaultTimeZone = loc
client, err := odoo.NewClient(cli.String(newOdooURLFlag().Name), odoo.ClientOptions{UseDebugLogger: cli.Int(newLogLevelFlag().Name) >= 2})
if err != nil {
return err
}
server := web.NewServer(
client,
cli.String(newSecretKeyFlag().Name),
cli.String(newOdooDBFlag().Name),
versionInfo,
)
addr := cli.String(newListenAddress().Name)
if certPath := cli.String(newTLSCertFlag().Name); certPath != "" {
return server.Echo.StartTLS(addr, cli.String(newTLSCertFlag().Name), cli.String(newTLSKeyFlag().Name))
}
return server.Echo.Start(addr)
}
func newWebCommand() *cli.Command {
return &cli.Command{
Name: "web",
Usage: "Starts the web server",
Action: RunWebServer,
Flags: []cli.Flag{
newOdooURLFlag(),
newOdooDBFlag(),
newSecretKeyFlag(),
newListenAddress(),
newDefaultTimezoneFlag(),
newTLSCertFlag(),
newTLSKeyFlag(),
},
}
}